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-folded
和org-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.")))
我們可以縮小預期的結局正則表達式'] .'的東西更確定?例如,在'[fn ::'後面首次出現'] .' - 這意味着腳註內不能有第二對方括號。或者,也許我們可以說它將成爲第一個'''',在一個硬回報行結尾?是否可能存在多行(例如段落或更多),段落之間有空行?未來的解決方案考慮到這個腳註將不會被放在屬性抽屜裏面,它會被分開摺疊。 – lawlist 2014-02-06 04:14:45
腳註可能不在行尾。但腳註內不會有方括號。因此,第一次出現'''表示腳註結束。換句話說,讓我們繼續你的第一個建議。 – incandescentman 2014-02-06 04:21:46