Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dired-noselect): Support both lists and strings #257

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jcf
Copy link

@jcf jcf commented Feb 20, 2024

Dired supports both strings and lists in dired-noselect.

(defun dired-noselect (dir-or-list &optional switches)
  "Like `dired' but return the Dired buffer as value, do not select it."
  (or dir-or-list (setq dir-or-list default-directory))
  ;; This loses the distinction between "/foo/*/" and "/foo/*" that
  ;; some shells make:
  (let (dirname initially-was-dirname)
    (if (consp dir-or-list)
	(setq dirname (car dir-or-list))
      (setq dirname dir-or-list))
    (setq initially-was-dirname
	  (string= (file-name-as-directory dirname) dirname))
    (setq dirname (abbreviate-file-name
		   (expand-file-name (directory-file-name dirname))))
    (if find-file-visit-truename
	(setq dirname (file-truename dirname)))
    ;; If the argument was syntactically  a directory name not a file name,
    ;; or if it happens to name a file that is a directory,
    ;; convert it syntactically to a directory name.
    ;; The reason for checking initially-was-dirname
    ;; and not just file-directory-p
    ;; is that file-directory-p is slow over ftp.
    (if (or initially-was-dirname (file-directory-p dirname))
	(setq dirname  (file-name-as-directory dirname)))
    (if (consp dir-or-list)
	(setq dir-or-list (cons dirname (cdr dir-or-list)))
      (setq dir-or-list dirname))
    (dired-internal-noselect dir-or-list switches)))
GNU Emacs 29.2 (build 1, aarch64-apple-darwin23.2.0, NS appkit-2487.30 Version 14.2.1 (Build 23C71))

oantolin/embark#701

@aikrahguzar
Copy link
Contributor

This will fix #249

Dired supports both strings and lists in dired-noselect.

oantolin/embark#701
@jcf
Copy link
Author

jcf commented Feb 23, 2024

I've pushed a revised solution as both the car of the list and the list itself are sometimes required depending on the function in the question.

@jcf jcf force-pushed the dired-noselect-consp branch from 64464df to 8d047a2 Compare February 23, 2024 12:27
((functionp dired-auto-revert-buffer)
(when (funcall dired-auto-revert-buffer dir) (revert-buffer))))
((functionp dired-auto-revert-buffer)
(when (funcall dired-auto-revert-buffer dir) (revert-buffer))))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whitespace change is perhaps a little overzealous. I can remove if preferred.

"Return buffer for DIR with FLAGS, FN is `dired-noselect'."
(let* ((key (file-name-as-directory (expand-file-name dir)))
(let* ((dir (if (consp dir-or-list) (car dir-or-list) dir-or-list))
(key (file-name-as-directory (expand-file-name dir)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to expand-file-name expects a string.

hlissner added a commit to hlissner/dirvish that referenced this pull request Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants