【问题标题】:Open Org Capture buffer in specific window?在特定窗口中打开 Org Capture 缓冲区?
【发布时间】:2019-01-15 03:16:15
【问题描述】:

我已经成为 Emacs 用户大约一年左右了。我通常为每个会话设置相同的窗口(四个窗口)。

我已经设置了捕获模板并且可以捕获我想要的内容,但是:我希望选择的捕获模板在新的(第五个)窗口中打开,而不是暂时将我从窗口设置中拉出来,保留我现有的布局。我通常希望捕获模板打开一段时间,所以它具有破坏性。

似乎是一个显而易见的选择,但我想不通。在此先感谢所有 Emacs 负责人。

【问题讨论】:

  • this answer 做你想做的事吗?
  • @legoscia 不,不幸的是。那个“已批准”的答案不起作用,并且 cmets 中的链接也不起作用。
  • @James:我刚刚尝试在@legoscia 指出的答案中注释掉org-capture-place-template 中的(delete-other-windows),并且效果很好:捕获缓冲区在现有窗口之一中打开,其他窗口保持不变,当捕获完成时,修改后的窗口进入其先前状态。但是,您不应从该答案中复制该功能:您应该编辑 you 正在使用的org-capture.el 文件,如果您正在使用已编译的代码运行,则可能重新编译该文件,然后执行M-x org-reload 以激活变化。
  • 正如我所说,这不是配置:您必须修改org-capture-place-template 函数。但是您确实在某处有 file org-capture.el:请通过 M-x locate-file org-capture.el 找到它。然后你可以编辑它,保存它,必要时编译它并重新加载org-mode。但我知道您可能会觉得这有点不知所措:您可以尝试以下@legoscia 的答案,可以添加到您的.emacs
  • @NickD 啊,现在我明白了。我找到了org-capture.el,并像你描述的那样注释掉了delete-other-windows——它奏效了。我不知道包的目录/文件结构,但现在我也了解了这一点。感谢您的回复,非常感谢。如果

标签: emacs org-mode


【解决方案1】:

我为链接的问题想出了一个更易于使用的Dan's answer 版本:

(defun my-org-capture-place-template-dont-delete-windows (oldfun &rest args)
  (cl-letf (((symbol-function 'delete-other-windows) 'ignore))
    (apply oldfun args)))

(with-eval-after-load "org-capture"
  (advice-add 'org-capture-place-template :around 'my-org-capture-place-template-dont-delete-windows))

也就是说,在调用org-capture-place-template 时,这段代码临时将delete-other-windows 重新定义为ignore,而不是修改组织模式代码并删除对delete-other-windows 的调用。

它并不完全符合您的要求:它选择现有窗口之一并将捕获缓冲区放在那里。至少它比删除除一个以外的所有先前窗口的默认行为要好。

可能有一种方法可以通过自定义变量display-buffer-alist 来做你想做的事,但我想不通...

【讨论】:

  • 谢谢您,您最初链接的文章有效,曾经@NickD 解释了有关修改org-capture.el 的详细信息。如果您最初的评论是一个答案,我会将其标记为最佳答案。
  • 我认为你应该接受这个答案:它包含指向另一个答案的指针,它还包含一种实现其他答案的道德等价物的方法,而无需自己修改组织来源。您可能应该尝试将上述答案中的代码添加到您的 .emacs 中,并且notorg-capture.el 进行修改。这将使您不必在每次升级 org-mode 版本时都进行相同的修改。
  • @NickD 同意。完成。
  • 您也可以使用 el-patch 在加载后修补 org-capture,如下所示: (el-patch-feature org-capture) (with-eval-after-load 'org-capture (el- patch-defun org-capture-place-template (&optional inhibitor-wconf-store) "在目标位置插入模板,并显示缓冲区。`inhibit-wconf-store'时,不存储窗口配置,如它之前可能已存储。”(除非禁止 wconf-store(org-capture-put :return-to-wconf(当前窗口配置)))(el-patch-remove(删除其他窗口)) )
  • 我试过这个但是得到org-set-local的函数定义无效的错误
【解决方案2】:

您也可以在加载后使用https://github.com/raxod502/el-patch 和补丁 org-capture(查找 (el-patch-remove (delete-other-windows))):

  (el-patch-feature org-capture) 
  (with-eval-after-load 'org-capture
    (el-patch-defun org-capture-place-template  (&optional inhibit-wconf-store)
      "Insert the template at the target location, and display the buffer.
When `inhibit-wconf-store', don't store the window configuration, as it
may have been stored before."
      (unless inhibit-wconf-store
    (org-capture-put :return-to-wconf (current-window-configuration)))
      (el-patch-remove (delete-other-windows))
      (org-switch-to-buffer-other-window
       (org-capture-get-indirect-buffer (org-capture-get :buffer) "CAPTURE"))
      (widen)
      (org-show-all)
      (goto-char (org-capture-get :pos))
      (setq-local outline-level 'org-outline-level)
      (pcase (org-capture-get :type)
    ((or `nil `entry) (org-capture-place-entry))
    (`table-line (org-capture-place-table-line))
    (`plain (org-capture-place-plain-text))
    (`item (org-capture-place-item))
    (`checkitem (org-capture-place-item)))
      (org-capture-mode 1)
      (setq-local org-capture-current-plist org-capture-plist)) ) 

【讨论】:

    【解决方案3】:

    由于某种原因,@legoscia 方法在 emacs 28 中对我来说失败了。

    所以这里是el-patch sn-p 如前所述:

    (el-patch-feature org-capture)
    (with-eval-after-load 'org-capture
      (el-patch-define-and-eval-template
        (defun org-capture-place-template)
        (el-patch-remove (delete-other-windows))))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      • 1970-01-01
      • 2023-03-21
      • 2020-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-05-29
      相关资源
      最近更新 更多