Emacs 组织模式 : textual reference to a file:line

标签 emacs lisp org-mode bookmarks

我在 Emacs 中使用 org-mode 来记录我的开发事件。我必须不断地手工完成的任务之一是描述代码区域。 Emacs 有一个非常好的 Bookmark List : 使用CTRL-x r m 创建书签,使用CTRL 列出它们-x r l。这非常有用,但不是我所需要的。

org-mode有链接的概念,命令org-store-link会在任意文件中记录一个指向当前位置的链接,可以粘贴到org-file中。这个问题有两个方面:

  • 它被存储为一个组织链接,链接的位置不直接可见(只是描述)。
  • file/search的格式存储,这不是我想要的。

我需要文本形式的书签,以便我可以将其复制粘贴到 org-mode 中,并在需要时结束编辑,使用如下简单格式:

absolute-file-path:line

而这个必须是从当前点位置获取的。工作流程将非常简单:

  • 转到我要记录的位置
  • 调用函数:position-to-kill-ring(我会将它绑定(bind)到键盘快捷键)
  • 转到 org-mode 缓冲区。
  • 猛拉位置。
  • 根据需要进行编辑(有时我需要通过相对路径更改绝对路径,因为我的代码位于不同机器的不同位置)

不幸的是我的 lisp 不存在,所以我不知道该怎么做。我的问题有简单的解决方案吗?

最佳答案

(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)))))

关于Emacs 组织模式 : textual reference to a file:line,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10681766/

相关文章:

emacs - 在 Emacs 中,您可以评估 Emacs Lisp 表达式并将其替换为结果吗?

emacs - 如何指定大(多行)表?

emacs - 如何在 org-mode 中逐行评估代码?

emacs 射弹 - 在目录中时显示 "you are not in a project"

emacs - Org LaTeX 预览在视网膜显示器上是模糊的

erlang - 如何在 Ubuntu Karmic 上安装 LFE?

scheme - 如何在 Scheme 中列出评估的所有中间步骤

emacs - 无法在组织模式下正确禁用 Flyspell

emacs - 奇怪的 Emacs 高亮问题

scheme - SICP - 程序与过程