emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using orgstruct-mode (or just org-cycle) in emacs-lisp-mode
@ 2015-11-08 15:02 Jonas Bernoulli
  2015-11-08 15:24 ` Nicolas Goaziou
  0 siblings, 1 reply; 14+ messages in thread
From: Jonas Bernoulli @ 2015-11-08 15:02 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-12-01 20:06 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-08 15:02 Using orgstruct-mode (or just org-cycle) in emacs-lisp-mode Jonas Bernoulli
2015-11-08 15:24 ` 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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).