在组织模式下,如何折叠/隐藏脚注? [英] in org-mode, how to fold/hide footnotes?

查看:215
本文介绍了在组织模式下,如何折叠/隐藏脚注?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Emacs组织模式下,是否有一种方法可以获得内嵌的脚注定义以显示为折叠?



所以例如,这样一行:

 效果是由于弱关系的力量[fn :: Newman,Mark,Albert-LászlóBarabási和Duncan J. Watts。 2006.网络结构与动力学。普林斯顿大学出版社]。 

可能只是这样:

 这种效应是由于弱关系的力量[✭]。 

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

解决方案

INITIAL (2014年2月6日):第一个工作草案。



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



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



在相关问题上(即完全隐藏属性抽屉,包括单词:PROPERTIES:),请参考以下主题:完全隐藏:属性:组织模式中的抽屉



在半相关问题(即,创建一个自定义块以进行代码折叠),另请参见: https://tex.stackexchange.com/a/161196 / 26911



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

修改 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-周期。这个解决方案中的代码的两个 defalias 部分需要一切正常工作。用户也可以直接在标题或副标题的开始处直接调用交互功能: Mx org-cycle RET



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

 (require'org)

(defalias 'org-cycle-hide-draers'lawlist-block-org-cycle-hide-draers)

(defun lawlist-block-org-cycle-hide-draers(state)

(当
(和
(derived-mode-p'org-mode)
(不是)时,重新隐藏所有抽屉,脚注或html块。 (memq state'(概述折叠内容))))
(save-excursion
(let *(
(globalp(memq state'(contents all)))
(如果globalp(point-min)(point)))
(end
(cond
(globalp
(point-max))
((eq状态'儿童)
(save-excursion(outline-next-heading)(point)))
(t(org-end-of-subtree t)))))
(goto-char beg)
(while
(re-search-forward
。* \\\ [fn\\ | ^ \\#\\ + BEGIN_HTML。* $ \\ | ^ [\t] *:PROPERTIES:[\t] * $end t )
(lawlist-org-flag t))))))

(defalias'org-cycle-internal-local'lawlist-block-org-cycle-internal-local)

(defun lawlist-block-org-cycle-internal-local()
执行本地循环操作
(let((goal-column 0)eoh eol eos有孩子的孩子跳过结构)
(save-excursion
(if(org-at-item-p)
(progn
(行首)
(setq struct(org-list-struct))
(setq eoh(point-at-eol))
(setq eos(org-list-get-item-end-before-blank点())
(setq has-children(org-list-has-child-p(point)struct)))
(org-back-to-heading)
eoh(保存游览(outl (点)))
(setq eos(save-excursion(1-(org-end-of-subtree tt))))
(setq has-children
(或
(save-excursion
(let((level(funcall outline-level)))
(outline-next-heading)
(和
(org-at-heading-p t)
(> (funcall outline-level)level))))
(save-excursion
(org-list-search-forward(org-item-begin-re)eos t)))))
(开始行2)
(if(featurep'xemacs)
(而
(和
(not(eobp))
(get-char -property(1-(point))'invisible))
(行首2))
(而
(和
(not(eobp))
(get-char-property(1-(point))'invisible))
(goto-char(next-char-property-change(point)'invisible))

(eolp)
(行首2))))
(setq eol(point)))
(cond
((= eos eoh)
(除非是前一个标题-p)
(run-hook-with-args'org-pre-cycle-hook'empty))
(org-unlogged-消息EMPTY ENTRY)
(setq org-cycle-subtree-status nil)
(save-excursion
(goto-char eos)
(outline-next-heading)
(if(outline-invisible-p)
(org-flag-heading nil) ))
(和
(或
(> = eol eos)
(not(string-match\\\S-(buffer-substring eol eos))))
(或
has-children
(not(setq children-skipped
org-cycle-skip-children-state-if-no-children)) )
(除非(org-before-first-heading-p)
(run-hook-with-args'org-pre-cycle-hook'children))
(if org-at-item-p)
;;然后
(org-list-set-item-visibility(point-at-bol)struct'children)
;;
(org-show-entry)
(org-with-limited-levels(show-children))
(when(eq org-cycle-include-plain-lists'integration)
(save-excursion
(org-back-to-heading)
(while(org-list-search-forward(org-item-begin-re)eos t)
(start-of-line 1)
(let *(
(struct(org-list-struct))
(prevs(org-list-prevs-alist struct))
(end(org-list-get-bottom-point struct)))
(map(lambda(e)(org-list-set-item-visibility e struct'folding))
()()()())))))
(org-unlogged-消息CHILDREN)
(save-excursion
(goto-char eos)
(outline-next-heading)
(if(outline-invisible-p)
(org-flag-heading nil)))
(setq org-cycle-subtree-status'children)
(除非(org-before-first-heading-p)
钩子与args'org-cycle-hook'children)))
((或
children-skipped
(和
(eq last-command this-command)
(eq org-cycle-subtree-status'children)))
(除非(org-before-first-heading-p)
(run-hook-with-args'org-pre -cycle-hook'subtree))
(outline-flag-region eoh eos nil)
(org-unlogged-message
(if children-skipped
SUBTREE(NO CHILDREN )
SUBTREE))
(setq org-cycle-subtree-status'subtree)
(除非(org-before-first-heading-p)
-hook-with-args'org-cycle-hook'subtree)))
((eq org-cycle-subtree-status'subtree)
(org-show-subtree)
消息ALL)
(setq org-cyc le-subtree-status'all))
(t
(run-hook-with-args'org-pre-cycle-hook'folding)
(outline-flag-region eoh eos
(org-unlogged-messageFOLDED)
(setq org-cycle-subtree-status'folding)
(除非(org-before-first-heading-p)
(run-hook-with-args'org-cycle-hook'folding))))))

(defun lawlist-org-flag(flag)
当FLAG不为零,隐藏下列任何一种:html代码块;
脚注或属性抽屉。
(save-excursion
(行首1)
(cond
((look-at。* \\ [fn )
(let *(
(begin(match-end 0))
end-footnote)
(if(re-search-forward\\]
(save-excursion(outline-next-heading)(point))t)
(progn
(setq end-footnote(point))
(outline-flag-region开始end-footnote标志))
(用户错误从%s开始出错begin))))
((查看^ \\#\\ + BEGIN_HTML。* $ \\ | ^ [\t] *:PROPERTIES:[\t] * $)
(let *((begin(match-end 0)))
(if(re-search-forward^ \\#\\ + END_HTML。* $ \\ | ^ [\t] *:END:
(save-excursion -next-heading)(point))t)
(outline-flag-region begin(point-at-eol)flag)
(用户错误呃从开始点%s开始。))))))

(defun lawlist-toggle-block-visibility()
要使这个函数正常工作,与正则表达式同一行。
(interactive)
(如果
(save-excursion
(开始行1)
(查看
。* \\ [fn\\ | ^ \\#\\ + BEGIN_HTML。* $ \\ | ^ [\t] *:PROPERTIES:[\\ \\ $]
(lawlist-org-flag(not(get-char-property(match-end 0)'invisible)))
(message对不起,你不是一行包含开始的正则表达式。)))


In Emacs org-mode, is there a way to get inline footnote definitions to appear as collapsed?

So that for instance, a line like this:

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].

might simply appear like this:

This effect is due to the strength of weak ties[✭].

I would also need a command to show the footnotes when necessary. So maybe what is needed are two commands: org-hide-footnotes and org-show-footnotes.

解决方案

INITIAL (February 6, 2014):   First working draft.

EDIT February 18, 2014:  Revised the function lawlist-toggle-block-visibility so that it contains a proper if/then/else statement -- i.e., if the line contains the requisite beginning region regexp, then the block visibility will be toggled, else a message saying sorry . . . . Added a citation to a related thread for code folding. Revised the error message to refer to a point rather than a line.

The source code for the answer below is also stored on Github: https://github.com/lawlist/lawlist-org-block-toggle/blob/master/lawlist-org-block-toggle.el

On a related issue (i.e., to completely hide the properties drawer including the word :PROPERTIES:), please refer to the following thread: Completely hide the :PROPERTIES: drawer in org-mode

On a semi-related issue (i.e., to create a custom block to be code-folded), see also: https://tex.stackexchange.com/a/161196/26911

This solution was tested with a fairly recent version of Emacs Trunk (built on January 19, 2014), which contains org-mode version 8.2.5c. Inasmuch as the :PROPERTIES: drawer through its :END: gets folded separately from the footnotes and the html blocks, this solution contemplates that the footnote and/or html code blocks will not be anywhere inside that properties drawer. The footnote can appear anywhere in the text paragraph, but cannot have another pair of square brackets inside the footnote -- since this code looks for the first ending square bracket in order to mark the end of the folded region. This code contemplates that #+BEGIN_HTML and #+END_HTML will both be flush-left with the left-hand margin. The startup views still work the same way -- e.g., the variables org-startup-folded and org-hide-block-startup.

The modification of org-cycle-internal-local enables tab cycling for all forms of folding in org-mode. All we did was fix the pagination of the function to make it more readable, and added the following condition: ((eq org-cycle-subtree-status 'subtree) (org-show-subtree) (message "ALL") (setq org-cycle-subtree-status 'all)). The interactive function org-cycle is still used to tab cycle between all of the various folded / unfolded views. The function lawlist-block-org-cycle-internal-local is a non-interactive supporting function that is used by org-cycle. The two defalias portions of the code in this solution are needed for everything to work properly. Rather than using tab cycling, the user can also call the interactive function directly at the beginning of the headings or subheadings with: M-x org-cycle RET

To toggle visibility of the footnote or html block directly, we use the interactive function lawlist-toggle-block-visibility. Place the cursor anywhere on the line containing the beginning of the footnote or, the beginning of the html block, and type: M-x lawlist-toggle-block-visibility RET

(require 'org)

(defalias 'org-cycle-hide-drawers 'lawlist-block-org-cycle-hide-drawers)

(defun lawlist-block-org-cycle-hide-drawers (state)
  "Re-hide all drawers, footnotes or html blocks after a visibility state change."
  (when
    (and
      (derived-mode-p 'org-mode)
      (not (memq state '(overview folded contents))))
    (save-excursion
      (let* (
          (globalp (memq state '(contents all)))
          (beg (if globalp (point-min) (point)))
          (end
            (cond
              (globalp
                (point-max))
              ((eq state 'children)
                (save-excursion (outline-next-heading) (point)))
              (t (org-end-of-subtree t)) )))
        (goto-char beg)
        (while
          (re-search-forward
            ".*\\[fn\\|^\\#\\+BEGIN_HTML.*$\\|^[ \t]*:PROPERTIES:[ \t]*$" end t)
          (lawlist-org-flag t))))))

(defalias 'org-cycle-internal-local 'lawlist-block-org-cycle-internal-local)

(defun lawlist-block-org-cycle-internal-local ()
  "Do the local cycling action."
  (let ((goal-column 0) eoh eol eos has-children children-skipped struct)
    (save-excursion
      (if (org-at-item-p)
        (progn
          (beginning-of-line)
          (setq struct (org-list-struct))
          (setq eoh (point-at-eol))
          (setq eos (org-list-get-item-end-before-blank (point) struct))
          (setq has-children (org-list-has-child-p (point) struct)))
        (org-back-to-heading)
        (setq eoh (save-excursion (outline-end-of-heading) (point)))
        (setq eos (save-excursion (1- (org-end-of-subtree t t))))
        (setq has-children
          (or
            (save-excursion
              (let ((level (funcall outline-level)))
                (outline-next-heading)
                (and
                  (org-at-heading-p t)
                  (> (funcall outline-level) level))))
            (save-excursion
              (org-list-search-forward (org-item-beginning-re) eos t)))))
      (beginning-of-line 2)
      (if (featurep 'xemacs)
        (while
            (and
              (not (eobp))
              (get-char-property (1- (point)) 'invisible))
          (beginning-of-line 2))
        (while
            (and
              (not (eobp))
              (get-char-property (1- (point)) 'invisible))
          (goto-char (next-single-char-property-change (point) 'invisible))
          (and
            (eolp)
            (beginning-of-line 2))))
      (setq eol (point)))
    (cond
      ((= eos eoh)
        (unless (org-before-first-heading-p)
          (run-hook-with-args 'org-pre-cycle-hook 'empty))
        (org-unlogged-message "EMPTY ENTRY")
        (setq org-cycle-subtree-status nil)
        (save-excursion
          (goto-char eos)
          (outline-next-heading)
          (if (outline-invisible-p)
            (org-flag-heading nil))))
      ((and
          (or
            (>= eol eos)
            (not (string-match "\\S-" (buffer-substring eol eos))))
          (or
            has-children
            (not (setq children-skipped
              org-cycle-skip-children-state-if-no-children))))
        (unless (org-before-first-heading-p)
          (run-hook-with-args 'org-pre-cycle-hook 'children))
        (if (org-at-item-p)
          ;; then
          (org-list-set-item-visibility (point-at-bol) struct 'children)
          ;; else
          (org-show-entry)
          (org-with-limited-levels (show-children))
          (when (eq org-cycle-include-plain-lists 'integrate)
            (save-excursion
              (org-back-to-heading)
              (while (org-list-search-forward (org-item-beginning-re) eos t)
                (beginning-of-line 1)
                (let* (
                    (struct (org-list-struct))
                    (prevs (org-list-prevs-alist struct))
                    (end (org-list-get-bottom-point struct)))
                  (mapc (lambda (e) (org-list-set-item-visibility e struct 'folded))
                    (org-list-get-all-items (point) struct prevs))
                  (goto-char (if (< end eos) end eos)))))))
        (org-unlogged-message "CHILDREN")
        (save-excursion
          (goto-char eos)
          (outline-next-heading)
          (if (outline-invisible-p)
            (org-flag-heading nil)))
        (setq org-cycle-subtree-status 'children)
        (unless (org-before-first-heading-p)
          (run-hook-with-args 'org-cycle-hook 'children)))
      ((or
          children-skipped
          (and
            (eq last-command this-command)
            (eq org-cycle-subtree-status 'children)))
        (unless (org-before-first-heading-p)
          (run-hook-with-args 'org-pre-cycle-hook 'subtree))
        (outline-flag-region eoh eos nil)
        (org-unlogged-message
        (if children-skipped
          "SUBTREE (NO CHILDREN)"
          "SUBTREE"))
        (setq org-cycle-subtree-status 'subtree)
        (unless (org-before-first-heading-p)
          (run-hook-with-args 'org-cycle-hook 'subtree)))
      ((eq org-cycle-subtree-status 'subtree)
        (org-show-subtree)
        (message "ALL")
        (setq org-cycle-subtree-status 'all))
      (t
        (run-hook-with-args 'org-pre-cycle-hook 'folded)
        (outline-flag-region eoh eos t)
        (org-unlogged-message "FOLDED")
        (setq org-cycle-subtree-status 'folded)
        (unless (org-before-first-heading-p)
        (run-hook-with-args 'org-cycle-hook 'folded))))))

(defun lawlist-org-flag (flag)
  "When FLAG is non-nil, hide any of the following:  html code block;
footnote; or, the properties drawer.  Otherwise make it visible."
  (save-excursion
    (beginning-of-line 1)
    (cond
      ((looking-at ".*\\[fn")
        (let* (
          (begin (match-end 0))
          end-footnote)
          (if (re-search-forward "\\]"
                (save-excursion (outline-next-heading) (point)) t)
            (progn
              (setq end-footnote (point))
              (outline-flag-region begin end-footnote flag))
            (user-error "Error beginning at point %s." begin))))
      ((looking-at "^\\#\\+BEGIN_HTML.*$\\|^[ \t]*:PROPERTIES:[ \t]*$")
        (let* ((begin (match-end 0)))
          (if (re-search-forward "^\\#\\+END_HTML.*$\\|^[ \t]*:END:"
                (save-excursion (outline-next-heading) (point)) t)
            (outline-flag-region begin (point-at-eol) flag)
            (user-error "Error beginning at point %s." begin)))))))

(defun lawlist-toggle-block-visibility ()
"For this function to work, the cursor must be on the same line as the regexp."
(interactive)
  (if
      (save-excursion
        (beginning-of-line 1)
          (looking-at
            ".*\\[fn\\|^\\#\\+BEGIN_HTML.*$\\|^[ \t]*:PROPERTIES:[ \t]*$"))
    (lawlist-org-flag (not (get-char-property (match-end 0) 'invisible)))
    (message "Sorry, you are not on a line containing the beginning regexp.")))

这篇关于在组织模式下,如何折叠/隐藏脚注?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆