我自己是一个 elisp 初学者,我认为它是一个很好的练习,瞧:
编辑:使用格式方法重写它,但我仍然认为不将其存储到杀戮环对我的工作流程的干扰较小(不了解你)。我还添加了添加列位置的功能。
(defvar current-file-reference "" "Global variable to store the current file reference")
(defun store-file-line-and-col ()
"Stores the current file, line and column point is at in a string in format \"file-name:line-number-column-number\". Insert the string using \"insert-file-reference\"."
(interactive)
(setq current-file-reference (format "%s:%d:%d" (buffer-file-name) (line-number-at-pos) (current-column))))
(defun store-file-and-line ()
"Stores the current file and line oint is at in a string in format \"file-name:line-number\". Insert the string using \"insert-file-reference\"."
(interactive)
(setq current-file-reference (format "%s:%d" (buffer-file-name) (line-number-at-pos))))
(defun insert-file-reference ()
"Inserts the value stored for current-file-reference at point."
(interactive)
(if (string= "" current-file-reference)
(message "No current file/line/column set!")
(insert current-file-reference)))
没有经过广泛测试,但为我工作。只需点击store-file-and-line或store-file-line-and-col来存储当前位置和insert-file-reference以在点插入存储的值。