Emacs 区分具有扩展名的文件、隐藏文件和无扩展名的文件
我很难区分有扩展名的文件、没有扩展名的文件和隐藏文件。我在dired模式下使用Emacs 区分具有扩展名的文件、隐藏文件和无扩展名的文件,emacs,elisp,dired,Emacs,Elisp,Dired,我很难区分有扩展名的文件、没有扩展名的文件和隐藏文件。我在dired模式下使用(文件扩展名(dired get file for visit)),文件扩展名的类型决定了要执行的操作,例如,在Emacs中打开,或使用特定应用程序从外部打开 隐藏文件(例如,.hidden)返回值nil,而不是“hidden” 没有扩展名的文件(例如,foo)也会返回值nil 有人能建议一种替代方法来处理这个问题吗 (let* ( (input-regexp '("odt" "wpd" "docx" "doc
(文件扩展名(dired get file for visit))
,文件扩展名的类型决定了要执行的操作,例如,在Emacs中打开,或使用特定应用程序从外部打开
隐藏文件(例如,.hidden
)返回值nil
,而不是“hidden”
没有扩展名的文件(例如,foo
)也会返回值nil
有人能建议一种替代方法来处理这个问题吗
(let* (
(input-regexp '("odt" "wpd" "docx" "doc" "xls" "pdf" "tif" "bmp" "jpg"))
(input-filename (dired-get-file-for-visit)) )
(if (not (regexp-match-p input-regexp (file-name-extension input-filename))))
(find-file input-filename) )
;; https://github.com/kentaro/auto-save-buffers-enhanced
(defun regexp-match-p (regexps string)
(catch 'matched
(dolist (regexp regexps)
(if (string-match regexp string)
(throw 'matched t)))))
以下是调试器(部分):
怎么样
(let* ((input-regexp '("odt" "wpd" "docx" "doc" "xls" "pdf" "tif" "bmp" "jpg"))
(input-filename (dired-get-file-for-visit))
(ext (file-name-extension input-filename)))
(unless (and ext (regexp-match-p input-regexp ext))
(find-file input-filename)))
或者,重新定义
(defun regexp-match-p (regexps string)
(and string
(catch 'matched
(let ((inhibit-changing-match-data t)) ; small optimization
(dolist (regexp regexps)
(when (string-match regexp string)
(throw 'matched t)))))))
两种解决方案都有效。我已经将你重新定义的功能添加到我的糖果袋中。非常感谢,非常感谢!您可以使用
string-match-p
而不是string-match
,因为您不使用匹配数据。
(defun regexp-match-p (regexps string)
(and string
(catch 'matched
(let ((inhibit-changing-match-data t)) ; small optimization
(dolist (regexp regexps)
(when (string-match regexp string)
(throw 'matched t)))))))