emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [RFC] Remove Org Struct mode


From: Adam Porter
Subject: Re: [O] [RFC] Remove Org Struct mode
Date: Wed, 23 Aug 2017 10:14:17 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Michael Brand <address@hidden> writes:

Hi Michael,

> First thank you for taking over maintenance of outshine.el from
> Thorsten Jolitz.

Well, I figured it was the least I could do, since he's put so much
effort into outshine, outorg, and navi-mode over the years.  Be advised,
although I am now the maintainer, I only comprehend a tiny fraction of
them; I learn more about them when I need to fix something, which so far
has hardly happened.  :)

> How can I collapse block-indented comments like a or b in the following?:
>
> ;; * Org
> (defun foo ()
>   ;; ** a
>   (bar)
>   ;; ** b
>   (beer))
> ;; * Calc
>
> orgstruct-mode supports it with orgstruct-heading-prefix-regexp set to
> for example " *;;;* ".

I don't think this is possible, or at least not easily.  The
outline-regexp variable says:

Regular expression to match the beginning of a heading.
Any line whose beginning matches this regexp is considered to start a heading.
Note that Outline mode only checks this regexp at the start of a line,
so the regexp need not (and usually does not) start with ‘^’.

So I think you would need to modify outline-mode to do this.

However, there are other ways to fold text besides
outline/outline-minor-mode/outshine.  You could probably do it fairly
easily with the origami package.

Or you could do what I do: I modify outline-regexp and outline-level so
that the asterisks aren't even necessary.  Instead, the heading level is
set by how many semicolons there are, e.g.:

;; Regular comment
;;; Heading level 1
;;;; Heading level 2
...

Then any comment that starts with 3 or more semicolons is indented to
the left edge and becomes a collapsible heading, regardless of the
indentation of the code under it.

#+BEGIN_SRC elisp
(defun ap/el-outline-level ()
  (or
   ;; Commented outline heading
   (and (string-match (rx
                       (* space)
                       (group (one-or-more (syntax comment-start)))
                       (one-or-more space))
                      (match-string 0))
        (- (match-end 0) (match-beginning 0) 1))

   ;; Lisp def heading
   ;; Add 8 (the highest standard outline level) to every keyword
   ;; heading
   (+ 8 (- (match-end 0) (match-beginning 0)))))

(defun ap/el-mode-outline-hook ()
  (setq outline-level 'ap/el-outline-level)
  (setq outline-regexp "\\(;;[;]\\{1,8\\} \\|\\((defun\\)\\)"))
  
(add-hook 'emacs-lisp-mode-hook 'ap/el-mode-outline-hook)
#+END_SRC

It works well for me, and it doesn't even require outshine IIRC, just
outline-minor-mode.  I've tried to make this work in other languages
too, like using the number of # characters for the outline level in
shell scripts, but I failed miserably, so I use outshine for other
languages.  It's easier in elisp since Emacs already treats
triple-semicolon comments as headings.

> A bit less important for me: How can I turn off syntax highlighting of
> headings, respectively generally in outshine.el?

Well, the first thing that comes to mind is to unset the properties of
the outline-level faces, but I'm not sure if you can do that per-buffer.
So you might try removing the outline-font-lock-keywords or
outline-font-lock-faces.

Hope this helps.

Adam




reply via email to

[Prev in Thread] Current Thread [Next in Thread]