Emacs——修改'dired mark',以防止在eob中将光标移动到空行

Emacs——修改'dired mark',以防止在eob中将光标移动到空行,emacs,elisp,dired,Emacs,Elisp,Dired,我有一个自定义函数,如果标记了多个文件名,或者如果只有一个文件名,则该函数将获取dired标记的文件名(即每个标记文件的名称)。每当光标位于无人区时,就会出现问题,因为方向标记(或我,因为我是飞行员)过于热衷于重复,并将光标移动到缓冲区末尾没有文件的空行。在这种情况下,错误如下: Debugger entered--Lisp error: (error "No file on this line") signal(error ("No file on this line")) error

我有一个自定义函数,如果标记了多个文件名,或者如果只有一个文件名,则该函数将获取dired标记的文件名(即每个标记文件的名称)。每当光标位于无人区时,就会出现问题,因为
方向标记
(或我,因为我是飞行员)过于热衷于重复,并将光标移动到缓冲区末尾没有文件的空行。在这种情况下,错误如下:

Debugger entered--Lisp error: (error "No file on this line")
  signal(error ("No file on this line"))
  error("No file on this line")
  dired-get-file-for-visit()
  (file-directory-p (dired-get-file-for-visit))
  (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename)))
  (lambda nil (interactive) (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename))))()
  funcall-interactively((lambda nil (interactive) (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename)))))
  call-interactively((lambda nil (interactive) (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename)))) nil nil)
  command-execute((lambda nil (interactive) (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename)))))
我喜欢按住
dired标记
键重复的功能,但我希望它在dired模式缓冲区中的最后一行停止。任何关于如何实现这一目标的想法都将不胜感激。越过该点,执行测试,然后返回到前一点似乎不是一种非常有效的处理方法。最好在最后一行的末尾用文件终止dired缓冲区,这样就没有空行了——也就是说,如果dired模式缓冲区的末尾没有空行,那么
dired mark
就不能到达那里(这样就好了?)


编辑:调试器消息已使用完整的回溯更新。以下是自定义函数,正如@Drew所说,它可能是我收到的错误消息的根本原因:

;; E-mail attachments using Wanderlust.
(define-key dired-mode-map (kbd "C-c e") (lambda () (interactive)
  ;; if hovering over a directory, then do nothing
  (unless (file-directory-p (dired-get-file-for-visit))
    (let ((lawlist-filename
      (if (or (re-search-backward "^*" nil t)
              (re-search-forward "^*" nil t))
        (dired-get-marked-files)
        (dired-get-file-for-visit))))
    (wl-draft-mailto)
    (attach-multiple-files lawlist-filename)))))

(defun attach-multiple-files (&optional lawlist-filename)
"Either (dired-get-marked-files) or (dired-get-file-for-visit) when exiting recursive edit."
(interactive)
  (let* (
      new-dir
      (beg (point))
      (dir "/Users/HOME/.0.data"))
      (goto-char (point-min))
    (when (and (re-search-forward "username@hostname.com" nil t) (not (re-search-forward "username@hostname.com\n" nil t)))
      (goto-char (point-max))
      (newline 2))
    (catch 'done
      (while t
        (goto-char (point-max))
        (let* (
          (multi-attach-variable t)
          (next-file
            (if lawlist-filename
              lawlist-filename
              (dired-read-file-name
                (if new-dir
                  new-dir
                  dir)))) )
          (setq new-dir
            (cond
              ((and next-file (stringp next-file))
                (file-name-directory next-file))
              ((and next-file (listp next-file))
                (file-name-directory (car next-file)))))
          (cond 
            ((stringp next-file)
              (mime-edit-insert-file next-file t))
            ((listp next-file)
              (mapcar (lambda (x) (mime-edit-insert-file x t)) next-file)))
          (setq lawlist-filename nil)
          (if (not (lawlist-y-or-n-p "Attach another? "))
                (progn
                  (goto-char beg)
                  (throw 'done nil))))))))

dired mark
上尝试
defadvice
,以避免在无人区着陆:

(defadvice dired-mark (after stop-at-last-file activate)
  (when (eobp)
    (previous-line 1)))

“标记后向前移动”功能被烘焙到
dired mark
(实际上,如果你想进入它的核心,可以进入
dired repeat over line
),因此此建议检查是否将你放在该空行上,如果是,则将你向后移动。你的最后一段暗示你可能对这个选项不太感兴趣,但我觉得它比改变dired的内部结构麻烦得多。

之前的答案(2014年10月17日):如果光标不在文件或目录上,并且没有标记任何内容,以下3行代码将停止该功能:

(当(空(dired-get-marked文件))
(let((退出时调试为零))
(信号“退出”(“您所在的行中没有包含有效的文件或目录。”))
修改后的答案(2015年1月20日):可以修改函数
直接插入目录
,删除缓冲区末尾的尾随新行和/或空白,如下所示:

Debugger entered--Lisp error: (error "No file on this line")
  signal(error ("No file on this line"))
  error("No file on this line")
  dired-get-file-for-visit()
  (file-directory-p (dired-get-file-for-visit))
  (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename)))
  (lambda nil (interactive) (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename))))()
  funcall-interactively((lambda nil (interactive) (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename)))))
  call-interactively((lambda nil (interactive) (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename)))) nil nil)
  command-execute((lambda nil (interactive) (if (file-directory-p (dired-get-file-for-visit)) nil (let ((lawlist-filename (if (or (re-search-backward "^*" nil t) (re-search-forward "^*" nil t)) (dired-get-marked-files) (dired-get-file-for-visit)))) (wl-draft-mailto) (attach-multiple-files lawlist-filename)))))
(转到字符(最大点))
(let((尾随空格+换行符(abs(向后跳过字符“\s\r\n\t”))))
(当(>尾随空格+换行符0)
(删除尾随字符的空格+换行符)))

1。您在哪里看到该错误消息?我没有在
emacs-Q中看到它,也没有在
dired标记中看到它
dired repeat over line
移动到eob时返回nil。消息来自于无文件行上的特定操作。若要避免此问题,请测试点是否与文件在同一行上。2.为什么要在eob之前停止--只是为了避免错误消息?(3.没有直接关系,但可能有兴趣:使用键
C-n
C-p
向下
向上
从结尾/开始到开始/结束进行换行。如果您愿意,您可以对
m
执行类似操作。)@Drew--谢谢您--我已经用自定义函数更新了这个问题,可能(如您所建议的)对错误负责(而不是
dired mark
)。在eob之前停止没有特别的原因,只是为了避免错误消息。有时我确实喜欢看Dired+,看看有什么好主意——我借用了你对Dired模式缓冲区的特别强调——这是一个很棒的库。@Drew——谢谢你帮助我解决这个问题。我使用的自定义函数是我在dired模式下获取文件名的早期尝试之一。在我的自定义库的其他地方,我已经切换到
dired do create files
使用的方法。因此,我在这个线程中讨论的自定义函数需要合并相同的方法。我已经发布了一个解决问题的答案。一如既往,非常感谢您的帮助!如果没有您的帮助,我可能会尝试在dired模式下不必要地重写某些内容。谢谢您的想法--我将在自定义函数的上下文中进一步考虑它,并向您报告。