2013-03-06 133 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.