Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Emacs 区分具有扩展名的文件、隐藏文件和无扩展名的文件_Emacs_Elisp_Dired - Fatal编程技术网

Emacs 区分具有扩展名的文件、隐藏文件和无扩展名的文件

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模式下使用
(文件扩展名(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)))))))