在组织模式中,如何折叠/隐藏脚注?

inc*_*man 5 lisp emacs elisp footnotes org-mode

在Emacs组织模式中,有没有办法让内联脚注定义显示为折叠?

例如,这样的一行:

This effect is due to the strength of weak ties[fn:: Newman, Mark, Albert-László Barabási, and Duncan J. Watts. 2006. The Structure and Dynamics of Networks. Princeton, NJ: Princeton University Press].
Run Code Online (Sandbox Code Playgroud)

可能只是这样:

This effect is due to the strength of weak ties[?].
Run Code Online (Sandbox Code Playgroud)

我还需要一个命令来在必要时显示脚注.所以可能需要的是两个命令:org-hide-footnotesorg-show-footnotes.

law*_*ist 2

初始(2014 年 2 月 6 日):\xc2\xa0 第一份工作草案。

\n\n

编辑2014年2月18日:\xc2\xa0修改了函数,lawlist-toggle-block-visibility使其包含正确的if/then/else语句——即,如果该行包含必需的开始区域正则表达式,则块可见性将被切换,否则一条消息说对不起 。。。。添加了对代码折叠相关线程的引用。修改了错误消息以引用点而不是线。

\n\n

以下答案的源代码也存储在 Github 上: https: //github.com/lawlist/lawlist-org-block-toggle/blob/master/lawlist-org-block-toggle.el

\n\n

关于相关问题(即,要完全隐藏包含单词 的属性抽屉:PROPERTIES:),请参阅以下线程: 在组织模式下完全隐藏 :PROPERTIES: 抽屉

\n\n

关于半相关问题(即创建要代码折叠的自定义块),另请参阅: https ://tex.stackexchange.com/a/161196/26911

\n\n

该解决方案使用最新版本的 Emacs Trunk(构建于 2014 年 1 月 19 日)进行了测试,其中包含 org-mode 版本 8.2.5c。由于:PROPERTIES:抽屉与:END:脚注和 html 块分开折叠,因此该解决方案考虑脚注和/或 html 代码块将不会位于该属性抽屉内的任何位置。脚注可以出现在文本段落中的任何位置,但脚注内不能有另一对方括号——因为此代码查找第一个结束方括号以标记折叠区域的末尾。此代码考虑到#+BEGIN_HTML#+END_HTML都将与左侧边距左齐平启动视图仍然以相同的方式工作——例如,变量org-startup-foldedorg-hide-block-startup

\n\n

的修改org-cycle-internal-local使制表符循环能够在组织模式下进行所有形式的折叠。我们所做的只是修复了函数的分页以使其更具可读性,并添加了以下条件: ((eq org-cycle-subtree-status \'subtree) (org-show-subtree) (message "ALL") (setq org-cycle-subtree-status \'all))。交互功能org-cycle仍然用于在所有各种折叠/展开视图之间进行选项卡循环。该功能是非交互式lawlist-block-org-cycle-internal-local支持功能,由. 为了使一切正常工作,需要此解决方案中的两部分代码。用户还可以直接在标题或副标题的开头调用交互函数,而不是使用选项卡循环: org-cycledefaliasM-x org-cycle RET

\n\n

要直接切换脚注或 html 块的可见性,我们使用交互功能lawlist-toggle-block-visibility。将光标放在包含脚注开头或html 块开头的 行上的任意位置,然后键入:M-x lawlist-toggle-block-visibility RET

\n\n
(require \'org)\n\n(defalias \'org-cycle-hide-drawers \'lawlist-block-org-cycle-hide-drawers)\n\n(defun lawlist-block-org-cycle-hide-drawers (state)\n  "Re-hide all drawers, footnotes or html blocks after a visibility state change."\n  (when\n    (and\n      (derived-mode-p \'org-mode)\n      (not (memq state \'(overview folded contents))))\n    (save-excursion\n      (let* (\n          (globalp (memq state \'(contents all)))\n          (beg (if globalp (point-min) (point)))\n          (end\n            (cond\n              (globalp\n                (point-max))\n              ((eq state \'children)\n                (save-excursion (outline-next-heading) (point)))\n              (t (org-end-of-subtree t)) )))\n        (goto-char beg)\n        (while\n          (re-search-forward\n            ".*\\\\[fn\\\\|^\\\\#\\\\+BEGIN_HTML.*$\\\\|^[ \\t]*:PROPERTIES:[ \\t]*$" end t)\n          (lawlist-org-flag t))))))\n\n(defalias \'org-cycle-internal-local \'lawlist-block-org-cycle-internal-local)\n\n(defun lawlist-block-org-cycle-internal-local ()\n  "Do the local cycling action."\n  (let ((goal-column 0) eoh eol eos has-children children-skipped struct)\n    (save-excursion\n      (if (org-at-item-p)\n        (progn\n          (beginning-of-line)\n          (setq struct (org-list-struct))\n          (setq eoh (point-at-eol))\n          (setq eos (org-list-get-item-end-before-blank (point) struct))\n          (setq has-children (org-list-has-child-p (point) struct)))\n        (org-back-to-heading)\n        (setq eoh (save-excursion (outline-end-of-heading) (point)))\n        (setq eos (save-excursion (1- (org-end-of-subtree t t))))\n        (setq has-children\n          (or\n            (save-excursion\n              (let ((level (funcall outline-level)))\n                (outline-next-heading)\n                (and\n                  (org-at-heading-p t)\n                  (> (funcall outline-level) level))))\n            (save-excursion\n              (org-list-search-forward (org-item-beginning-re) eos t)))))\n      (beginning-of-line 2)\n      (if (featurep \'xemacs)\n        (while\n            (and\n              (not (eobp))\n              (get-char-property (1- (point)) \'invisible))\n          (beginning-of-line 2))\n        (while\n            (and\n              (not (eobp))\n              (get-char-property (1- (point)) \'invisible))\n          (goto-char (next-single-char-property-change (point) \'invisible))\n          (and\n            (eolp)\n            (beginning-of-line 2))))\n      (setq eol (point)))\n    (cond\n      ((= eos eoh)\n        (unless (org-before-first-heading-p)\n          (run-hook-with-args \'org-pre-cycle-hook \'empty))\n        (org-unlogged-message "EMPTY ENTRY")\n        (setq org-cycle-subtree-status nil)\n        (save-excursion\n          (goto-char eos)\n          (outline-next-heading)\n          (if (outline-invisible-p)\n            (org-flag-heading nil))))\n      ((and\n          (or\n            (>= eol eos)\n            (not (string-match "\\\\S-" (buffer-substring eol eos))))\n          (or\n            has-children\n            (not (setq children-skipped\n              org-cycle-skip-children-state-if-no-children))))\n        (unless (org-before-first-heading-p)\n          (run-hook-with-args \'org-pre-cycle-hook \'children))\n        (if (org-at-item-p)\n          ;; then\n          (org-list-set-item-visibility (point-at-bol) struct \'children)\n          ;; else\n          (org-show-entry)\n          (org-with-limited-levels (show-children))\n          (when (eq org-cycle-include-plain-lists \'integrate)\n            (save-excursion\n              (org-back-to-heading)\n              (while (org-list-search-forward (org-item-beginning-re) eos t)\n                (beginning-of-line 1)\n                (let* (\n                    (struct (org-list-struct))\n                    (prevs (org-list-prevs-alist struct))\n                    (end (org-list-get-bottom-point struct)))\n                  (mapc (lambda (e) (org-list-set-item-visibility e struct \'folded))\n                    (org-list-get-all-items (point) struct prevs))\n                  (goto-char (if (< end eos) end eos)))))))\n        (org-unlogged-message "CHILDREN")\n        (save-excursion\n          (goto-char eos)\n          (outline-next-heading)\n          (if (outline-invisible-p)\n            (org-flag-heading nil)))\n        (setq org-cycle-subtree-status \'children)\n        (unless (org-before-first-heading-p)\n          (run-hook-with-args \'org-cycle-hook \'children)))\n      ((or\n          children-skipped\n          (and\n            (eq last-command this-command)\n            (eq org-cycle-subtree-status \'children)))\n        (unless (org-before-first-heading-p)\n          (run-hook-with-args \'org-pre-cycle-hook \'subtree))\n        (outline-flag-region eoh eos nil)\n        (org-unlogged-message\n        (if children-skipped\n          "SUBTREE (NO CHILDREN)"\n          "SUBTREE"))\n        (setq org-cycle-subtree-status \'subtree)\n        (unless (org-before-first-heading-p)\n          (run-hook-with-args \'org-cycle-hook \'subtree)))\n      ((eq org-cycle-subtree-status \'subtree)\n        (org-show-subtree)\n        (message "ALL")\n        (setq org-cycle-subtree-status \'all))\n      (t\n        (run-hook-with-args \'org-pre-cycle-hook \'folded)\n        (outline-flag-region eoh eos t)\n        (org-unlogged-message "FOLDED")\n        (setq org-cycle-subtree-status \'folded)\n        (unless (org-before-first-heading-p)\n        (run-hook-with-args \'org-cycle-hook \'folded))))))\n\n(defun lawlist-org-flag (flag)\n  "When FLAG is non-nil, hide any of the following:  html code block;\nfootnote; or, the properties drawer.  Otherwise make it visible."\n  (save-excursion\n    (beginning-of-line 1)\n    (cond\n      ((looking-at ".*\\\\[fn")\n        (let* (\n          (begin (match-end 0))\n          end-footnote)\n          (if (re-search-forward "\\\\]"\n                (save-excursion (outline-next-heading) (point)) t)\n            (progn\n              (setq end-footnote (point))\n              (outline-flag-region begin end-footnote flag))\n            (user-error "Error beginning at point %s." begin))))\n      ((looking-at "^\\\\#\\\\+BEGIN_HTML.*$\\\\|^[ \\t]*:PROPERTIES:[ \\t]*$")\n        (let* ((begin (match-end 0)))\n          (if (re-search-forward "^\\\\#\\\\+END_HTML.*$\\\\|^[ \\t]*:END:"\n                (save-excursion (outline-next-heading) (point)) t)\n            (outline-flag-region begin (point-at-eol) flag)\n            (user-error "Error beginning at point %s." begin)))))))\n\n(defun lawlist-toggle-block-visibility ()\n"For this function to work, the cursor must be on the same line as the regexp."\n(interactive)\n  (if\n      (save-excursion\n        (beginning-of-line 1)\n          (looking-at\n            ".*\\\\[fn\\\\|^\\\\#\\\\+BEGIN_HTML.*$\\\\|^[ \\t]*:PROPERTIES:[ \\t]*$"))\n    (lawlist-org-flag (not (get-char-property (match-end 0) \'invisible)))\n    (message "Sorry, you are not on a line containing the beginning regexp.")))\n
Run Code Online (Sandbox Code Playgroud)\n