From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonas Bernoulli Subject: Using orgstruct-mode (or just org-cycle) in emacs-lisp-mode Date: Sun, 08 Nov 2015 16:02:59 +0100 Message-ID: <87oaf4wn30.fsf@bernoul.li> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvRV2-0001Ld-Eb for emacs-orgmode@gnu.org; Sun, 08 Nov 2015 10:03:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvRUz-00062s-7m for emacs-orgmode@gnu.org; Sun, 08 Nov 2015 10:03:20 -0500 Received: from mail.hostpark.net ([212.243.197.30]:57839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvRUy-00062o-U9 for emacs-orgmode@gnu.org; Sun, 08 Nov 2015 10:03:17 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id EAD2F16A78 for ; Sun, 8 Nov 2015 16:03:13 +0100 (CET) Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail0.hostpark.net [127.0.0.1]) (amavisd-new, port 10124) with ESMTP id 0bAZV2tLaUne for ; Sun, 8 Nov 2015 16:03:13 +0100 (CET) Received: from hal (84-73-67-69.dclient.hispeed.ch [84.73.67.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id 92F2F16B32 for ; Sun, 8 Nov 2015 16:03:13 +0100 (CET) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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 =20 ... ;;; next heading instead of (when there is only code in the section) ;;; heading =20 (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) =20 (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)))) =20 (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 =E2=80=98orgstruct-heading-prefix-r= egexp=E2=80=99: > the regular expression must match the local prefix to use before Org=E2= =80=99s > headlines. For example, if you set this variable to =E2=80=98";; "=E2=80= =99 in Emacs > Lisp files, you will be able to fold and unfold headlines in Emacs Lisp > commented lines. Some commands like =E2=80=98org-demote=E2=80=99 are d= isabled 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