How can I use other heading styles like twiki ---+ or mediawiki == h2 == in org-mode?

流过昼夜 提交于 2019-12-07 02:15:06

问题


I really want to use org-mode.

But, I want to use org-mode to understand structured documents that have already been written using different heading syntax,

e.g. using twiki's ---+

---+ H1 

Top level

---++ H2

Nested

---+ H1 #2

Second top level

Or mediawiki like

= H1 = 

Top level

== H2 ==

Nested

= H1 #2 =

Second top level

I'd like to have all of the goodness of org-mode folding, etc., just using these different heading styles.


Actually, worse that that:

I would like, say, the twiki or mediawaiki headings to take priority over org mode asterisk headings. But I would like to have both in use.

= H1 =

Top level

* this is a list
** nested
* list
** nested

== H2 ==

Nested

= H1 #2 =

Second top level

--+ What I have tried so far

I have been able to use outline mode to handle twiki, for example via

---+ Emacs stuff
# try (defvar twiki-outline-regexp "---+\\++ \\|\\(\\(?:   \\)+\\)[0-9*] ")
Local Variables: ***
outline-regexp: "^---\\++" ***
org-outline-regexp: "^---\\++" ***
End: ***

However, org-outline-regexp doesn't do hwat I would hope.

emacs' outline-mode's out-level function looks almost exactly like what I want.

(defvar outline-level 'outline-level
  "*Function of no args to compute a header's nesting level in an outline.
It can assume point is at the beginning of a header line and that the match
data reflects the `outline-regexp'.")

i.e. instead of regexps, a generic function.

But I have not managed to make it work with org-mode. It looks like org-mode does not really use this, or, rather, has other stuff.

;; In Org buffers, the value of `outline-regexp' is that of
;; `org-outline-regexp'.  The only function still directly relying on
;; `outline-regexp' is `org-overview' so that `org-cycle' can do its
;; job when `orgstruct-mode' is active.
(defvar org-outline-regexp "\\*+ "
  "Regexp to match Org headlines.")
(defconst org-outline-regexp-bol "^\\*+ "
  "Regexp to match Org headlines.
This is similar to `org-outline-regexp' but additionally makes
sure that we are at the beginning of the line.")

(defconst org-heading-regexp "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$"
  "Matches an headline, putting stars and text into groups.
Stars are put in group 1 and the trimmed body in group 2.")

Failing this, well, the main thing that I want from org-mode is links, Asking another question here How can I "linkify" a non-org-mode buffer in emacs


回答1:


My frustration was simply that org-mode has different rules for what constitutes a new outline section than outline-mode does. It requires a space after the asterisks, so it doesn't work on my extensive collection of notes, which forgo those spaces.

I resolved that by removing the trailing space in the not-well-documented org-outline-regexp variable, which is used to initialize the buffer-local variable outline-regexp, and that seems to be working for me. E.g. (set-variable 'org-outline-regexp "\\*+")

As to your actual question, my guess is that other regexp's and code would have to change to handle radically different stuff like twiki or mediawiki headings.



来源:https://stackoverflow.com/questions/11697056/how-can-i-use-other-heading-styles-like-twiki-or-mediawiki-h2-in-org

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!