光标在绝对路经之上跳转

当前 buffer 如果存在绝对路经, 光标在绝对路经之上跳转.

从懒猫 thing-edit 复制粘贴后,做了微小改变.

大家有这样的跳转需求(么?) 又是如何完成的呢?

(defun jump-to-filename (kill-conditional)
  "Copy filename at current point.
With the universal argument, the text will also be killed"
  (interactive "P")
  (thing-edit 'filename kill-conditional)
  (find-file (substring-no-properties (nth 0 kill-ring))))

(defun thing-edit (thing &optional kill-conditional)
  "This function is a simple interface for `thing-edit-internal'.
If `KILL-CONDITIONAL' is non-nil, kill object,
otherwise copy object."
  (save-excursion
    (thing-edit-internal (beginning-of-thing thing)
                         (end-of-thing thing)
                         kill-conditional)))


(defun thing-edit-internal (object-beg object-end &optional kill-conditional)
  "A fast edit complexes object.
Argument OBJECT-BEG the begin position that object.
Argument OBJECT-END the end position of object.
Optional argument KILL-CONDITIONAL default is do copy handle, if KILL-CONDITIONAL is non-nil do cut handle."
  (interactive)
  (let ((pulse-iterations 1)
        (pulse-delay thing-edit-flash-line-delay))
    (cond (kill-conditional
           (when thing-edit-show-message-p
             (message "%s [ %s ]"
                      (propertize "Cut" 'face 'thing-edit-font-lock-action)
                      (buffer-substring object-beg object-end)))
           (kill-region object-beg object-end))
          (t
           (when thing-edit-show-message-p
             (message "%s [ %s ]"
                      (propertize "Copy" 'face 'thing-edit-font-lock-action)
                      (buffer-substring object-beg object-end)))
           ;; Flash before real copy operation.
           (pulse-momentary-highlight-region object-beg object-end 'thing-edit-font-lock-flash)
           (kill-ring-save object-beg object-end)))))


(defcustom thing-edit-flash-line-delay .3
  "How many seconds to flash `thing-edit-font-lock-flash' after navigation.
Setting this to nil or 0 will turn off the indicator."
  :type 'number
  :group 'thing-edit)

(defcustom thing-edit-show-message-p t
  "Set this option to nil if want thing-edit work silencely.
Default is nil."
  :type 'boolean
  :group 'thing-edit)

(defface thing-edit-font-lock-flash
  '((t (:inherit highlight)))
  "Face to flash the current line."
  :group 'thing-edit)

你这是需要 find-file-at-point 吧?

1 个赞

不知道是不是helm添加的功能,但是我在路径上find-file是可以跳转的,相对绝对路径都可以

1 个赞

我发现这是 helm 特有的,目前在 eshell 和 latex modes 里面都这么干了:

  (define-key LaTeX-mode-map (kbd "C-x C-f") 'helm-find-files)
  ;; copy from https://emacs-china.org/t/projectile-c-c-p-g/10251/4
  (advice-add 'helm-find-files :before
            (lambda (&rest _)
              (xref-push-marker-stack)))