bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#25942: 26.0.50; dired-mark-extension prepend '.' to suffix if not pr


From: Tino Calancha
Subject: bug#25942: 26.0.50; dired-mark-extension prepend '.' to suffix if not present
Date: Mon, 27 Mar 2017 10:30:26 +0900 (JST)
User-agent: Alpine 2.20 (DEB 67 2015-01-07)



On Mon, 27 Mar 2017, Juri Linkov wrote:

emacs -Q /tmp

(require 'dired-x)
(require 'ert)
;; Evaluate following sexp:
(let ((dirs '("Public" "Music"))
      (files '(".bashrc" "bar.c" "foo.c"))
      (dir (make-temp-file "Bug25942" 'dir)))
  (unwind-protect
      (progn
        (dolist (d dirs)
          (make-directory (expand-file-name d dir)))
        (dolist (f files)
          (write-region nil nil (expand-file-name f dir)))
        (dired dir)
        (dired-mark-extension "c")
        (should (= 2 (length (dired-get-marked-files)))))
    (delete-directory dir 'recursive)))

IMO, in this example looks better if just those files ending with
'.c' are marked i.e., to not mark 'Public' or 'Music'.

Is this a backward-compatible change?
Yes, it is; but it makes a better global picture when we consider
this function together with `file-name-extension' and
`file-name-sans-extension' (More below).

If not, then maybe better
prepend ‘.’ only to the default value for interactive uses? So users
will get the right result when using ‘M-x dired-mark-extension RET RET’.
But for the programmatic uses it's the responsibility of the caller to
supply the right suffix in ‘(dired-mark-extension ".c")’
The problem is that this command has a concept of 'extension' different than the two other functions mentioned above.
[Using same names than in my code snippet]:

(file-name-extension "Music")
=> nil
(equal "Music" (file-name-sans-extension "Music"))
=> t

(file-name-extension "foo.c")
=> "c"
;; Note: this command consider extension "c" (without period).

(dired-mark-extension (file-name-extension "foo.c"))
;; This marks all the files, i.e., also marks "Music" and "Public".

IMHO the correct behaviour for
(dired-mark-extension (file-name-extension "foo.c"))
would be to mark those files satisfying
(lambda (f) (equal (file-name-extension f) (file-name-extension "foo.c")))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]