dan*_*ast 8 lisp emacs bookmarks org-mode
我用org-mode它Emacs来记录我的开发活动.我必须不断手动完成的任务之一是描述代码区域.Emacs有一个非常好的书签列表:创建一个书签CTRL- x r m与列举了CTRL- x r l.这非常有用,但不是我需要的.
组织模式具有链接的概念,该命令org-store-link将记录任何文件中当前位置的链接,该链接可以粘贴到组织文件.这个问题有两方面:
file/search,这不是我想要的.我需要以文本形式提供书签,以便我可以将其粘贴到org-mode中,如果需要,可以使用以下简单格式结束编辑:
absolute-file-path:line
Run Code Online (Sandbox Code Playgroud)
这必须从当前的位置获得.工作流程非常简单:
position-to-kill-ring我将它绑定到键盘快捷键)org-mode缓冲区.不幸的是我lisp不存在,所以我不知道该怎么做.我的问题有一个简单的解决方案吗?
phi*_*ils 12
(defun position-to-kill-ring ()
"Copy to the kill ring a string in the format \"file-name:line-number\"
for the current buffer's file name, and the line number at point."
(interactive)
(kill-new
(format "%s:%d" (buffer-file-name) (save-restriction
(widen) (line-number-at-pos)))))
Run Code Online (Sandbox Code Playgroud)
你想使用org-create-file-search-functions和org-execute-file-search-functions钩子.
例如,如果您需要为文本模式文件描述的搜索,请使用以下命令:
(add-hook 'org-create-file-search-functions
'(lambda ()
(when (eq major-mode 'text-mode)
(number-to-string (line-number-at-pos)))))
(add-hook 'org-execute-file-search-functions
'(lambda (search-string)
(when (eq major-mode 'text-mode)
(goto-line (string-to-number search-string)))))
Run Code Online (Sandbox Code Playgroud)
然后M-x org-store-link RET将做正确的事情(存储行号作为搜索字符串)和C-c C-o(即M-x org-open-at-point RET)将打开文件并转到此行号.
您当然可以检查其他模式和/或条件.