From: Jonas Bernoulli <jonas@bernoul.li>
To: emacs-orgmode@gnu.org
Subject: Using orgstruct-mode (or just org-cycle) in emacs-lisp-mode
Date: Sun, 08 Nov 2015 16:02:59 +0100 [thread overview]
Message-ID: <87oaf4wn30.fsf@bernoul.li> (raw)
Hello,
Until a few months ago I was able to use `org-cycle' in
`emacs-lisp-mode' buffers, and it just worked after turning on
`outline-minor-mode' but not `orgstruct-mode'. I am using the
development versions of both Emacs (25.0.50) and Org (9.0).
But somewhere along the way `org-cycle' partially broke when used like
this. When switching to the CHILDREN state I now see this:
;;; heading
...
;;; next heading
instead of (when there is only code in the section)
;;; heading
(defun foo ()...
(defun bar ()...
;;; next heading
or (when there are subheadings)
;;; heading
;;;; sub-heading one...
;;;; sub-heading two...
;;; next heading
I would like to use `orgstruct-mode' in `emacs-lisp-mode' but I cannot
get it to work at all. So for now I would be happy if I could just use
`org-cycle' as I used to.
Finally I have gotten around to investigate this and came across this:
;; This is done in `emacs-lisp-mode':
(setq-local outline-regexp ";;;\\(;* [^ \t\n]\\|###autoload\\)\\|(")
(defun lisp-outline-level ()
"Lisp mode `outline-level' function."
(let ((len (- (match-end 0) (match-beginning 0))))
(if (looking-at "(\\|;;;###autoload")
1000
len)))
This doesn't make any sense to me. Maybe these values now take the
needs of `orgstruct-mode' into account, but when thinking just of
`outline-minor-mode', then I would expect something like this instead:
(setq-local outline-regexp "\\(;;;+ \\)\\|(")
(defun lisp-outline-level ()
(cond ((match-beginning 1) (- (length (match-string 1)) 2))
((match-beginning 0) 6)))
In addition to that I also had to add this for `org-cycle' to work in
`emacs-lisp-mode' again.
(add-hook 'org-cycle-hook 'org-cycle-elisp-kludge)
(defun org-cycle-elisp-kludge (state)
(when (and (eq state 'children)
(derived-mode-p 'emacs-lisp-mode))
(save-excursion
(goto-char eoh)
(beginning-of-line)
(outline-show-branches))))
(defun org-before-first-heading-p ()
(if (derived-mode-p 'emacs-lisp-mode)
nil ; in that mode the below always return t
(save-excursion
(end-of-line)
(null (re-search-backward org-outline-regexp-bol nil t)))))
Now, I am probably barking at the wrong tree here, but since I also
couldn't get `orgstruct-mode' to work at all, I just investigated the
code which I still somewhat understood, `orgstruct-setup' et al is
beyond me.
So I guess my questions are:
1. In what way does the default value of `outline-regexp' and the
definition of `lisp-outline-level' make sense?
2. How do I get from `emacs -Q' to TAB on a heading in `emacs-lisp-mode'
cycling though the tree states (with or without `orgstruct-mode').
The Org manual sais this:
> You can also use Org structure editing to fold and unfold headlines
> in _any_ file, provided you defined ‘orgstruct-heading-prefix-regexp’:
> the regular expression must match the local prefix to use before Org’s
> headlines. For example, if you set this variable to ‘";; "’ in Emacs
> Lisp files, you will be able to fold and unfold headlines in Emacs Lisp
> commented lines. Some commands like ‘org-demote’ are disabled when the
> prefix is set, but folding/unfolding will work correctly.
At least for me that wasn't the case at all (what keys do I have to
press to do the folding/unfolding?).
Thanks for your help,
Jonas
next reply other threads:[~2015-11-08 15:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-08 15:02 Jonas Bernoulli [this message]
2015-11-08 15:24 ` Using orgstruct-mode (or just org-cycle) in emacs-lisp-mode Nicolas Goaziou
2015-11-08 15:48 ` Jonas Bernoulli
2015-11-08 17:34 ` Aaron Ecay
2015-11-09 23:40 ` Jonas Bernoulli
2015-11-10 10:54 ` Rasmus
2015-12-01 20:06 ` Thorsten Jolitz
2015-11-08 17:36 ` Jorge A. Alfaro-Murillo
2015-11-09 23:30 ` Jonas Bernoulli
2015-11-14 8:37 ` Nicolas Goaziou
2015-11-18 9:57 ` Jonas Bernoulli
2015-11-19 8:39 ` Nicolas Goaziou
2015-11-19 19:50 ` Jonas Bernoulli
2015-11-19 21:47 ` Rasmus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87oaf4wn30.fsf@bernoul.li \
--to=jonas@bernoul.li \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.