2013-03-06 135 views
5

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

可能只是看起来像这样:

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

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

+0

我们可以缩小预期的结局正则表达式'] .'的东西更确定?例如,在'[fn ::'后面首次出现'] .' - 这意味着脚注内不能有第二对方括号。或者,也许我们可以说它将成为第一个'''',在一个硬回报行结尾?是否可能存在多行(例如段落或更多),段落之间有空行?未来的解决方案考虑到这个脚注将不会被放在属性抽屉里面,它会被分开折叠。 – lawlist 2014-02-06 04:14:45

+0

脚注可能不在行尾。但脚注内不会有方括号。因此,第一次出现'''表示脚注结束。换句话说,让我们继续你的第一个建议。 – incandescentman 2014-02-06 04:21:46

回答

2

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

编辑 2014年2月18日:修订功能lawlist-toggle-block-visibility以便它包含适当的if/then/else语句 - 也就是说,如果该行包含开始区域的正则表达式的必要,那么块的知名度将被切换,其他的消息说抱歉。 。 。 。为相关的代码折叠添加了引用。修改错误消息以引用一个点而不是一行。

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

另一个相关的问题(即,完全隐藏属性抽屉包括单词:PROPERTIES:),请参考以下主题:Completely hide the :PROPERTIES: drawer in org-mode

在半相关问题上(即,创建一个自定义的块为代码折叠),也见:https://tex.stackexchange.com/a/161196/26911

此溶液用)相当最新版本的Emacs干线的(建于2014年1月19日,其中包含组织模式8.2版进行测试。 5C。因为在抽屉:PROPERTIES:通过其:END:会从脚注和HTML块分别折叠,这种解决方案设想的脚注和/或HTML代码块将不是属性抽屉内的任何地方。脚注可以在文本段落的任何地方出现,但不能有另外一对括号脚注中的 - 因为这代码查找第一结束括号,以纪念翻折区域的末端。此代码设想#+BEGIN_HTML#+END_HTML都将是左对齐与左边距。启动视图仍然以相同的方式工作 - 例如变量org-startup-foldedorg-hide-block-startup

org-cycle-internal-local修饰使得标签循环用于所有形式的org-模式折叠的。我们所做的只是修改了函数的分页以使其更具可读性,并添加了以下条件:((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-cycle非交互式支撑功能。这个解决方案中代码的两个部分defalias是一切正常工作所必需的。用户也可以在标题或子标题的开头直接调用交互功能:M-x org-cycle RET

要直接切换脚注或html块的可见性,我们使用交互功能lawlist-toggle-block-visibility。将光标置于任何位置上包含脚注的开始或HTML内容的开始和类型的线路: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."))) 
+0

这似乎不再适用于我(和github链接已损坏)。特别是如果我在一条线上有多个脚注,它就完全失败了。你从那以后更新过吗?如果不是,我是否应该再次要求提供可见度以防其他人拥有? – avv 2018-01-21 05:49:10

3

我不认为这是可能的。同样使用TAB作为其中的扩展键可能会导致密钥的更多重载。

另一方面,有没有什么特别的理由不对脚注使用脚注部分?

C-c C-x f将创建/与您有任何脚注交互。

(ORG-脚注行动&可选SPECIAL)

做脚注正确的事情。

在脚注参考中,跳转到定义。

在定义时,跳转到引用(如果它们存在),否则请给 创建它们。

如果在定义或引用时未交互创建新的脚注 。

使用前缀arg SPECIAL,在菜单中提供附加命令。

的附加命令是:

 s Sort the footnote definitions by reference sequence. During editing, 
      Org makes no effort to sort footnote definitions into a particular 
      sequence. If you want them sorted, use this command, which will 
      also move entries according to org-footnote-section. Automatic 
      sorting after each insertion/deletion can be configured using the 
      variable org-footnote-auto-adjust. 
     r Renumber the simple fn:N footnotes. Automatic renumbering 
      after each insertion/deletion can be configured using the variable 
      org-footnote-auto-adjust. 
     S Short for first r, then s action. 
     n Normalize the footnotes by collecting all definitions (including 
      inline definitions) into a special section, and then numbering them 
      in sequence. The references will then also be numbers. This is 
      meant to be the final step before finishing a document (e.g., sending 
      off an email). The exporters do this automatically, and so could 
      something like message-send-hook. 
     d Delete the footnote at point, and all definitions of and references 
      to it.