0

I would like each org-mode section to be expandable with a left mouse click anywhere in the heading (excluding tags). This answer correctly points to org-mouse.

However, I must click on the section asterisks * to get the expansion behavior. The actual title is not clickable. For instance, if I want to display the content under the * Heading heading, clicking on the * expands the section, but clicking on Heading yields no result. The clickable area includes all asterisks (potentially more than one for sub-headings) and the single space between the asterisks and the heading. Is there a way to fix this?

2
  • Do you realize that hitting TAB anywhere on the heading expands it? Maybe that's enough and you don't need the mouse to do the same thing?
    – NickD
    Commented Mar 29 at 12:56
  • I'm aware, but occasionally it is more convenient to select the heading with the mouse. Commented Apr 4 at 12:46

1 Answer 1

1

This seems promising

(require 'org)
(defvar my-org-mouse-map (make-sparse-keymap))
(org-defkey my-org-mouse-map [mouse-1] 'org-cycle)

(add-hook 'org-mode-hook
          (defun my-org-mouse-map-hook ()
            (font-lock-add-keywords
             nil
             `((,(rx (and bol (one-or-more "*") (one-or-more space) (group-n 1 (one-or-more any)) eol))
                (0
                 `(
                   face nil
                   keymap ,my-org-mouse-map
                   mouse-face highlight
                   )
                 prepend)))
             t)))

TAB cycles across three states FOLDED, CHILDREN, and SUBTREE.

In the above <mouse-1> case above, it cycles between FOLDED and CHILDREN.

May be someone in the audience can refine the recipe for mouse-1 case ...

1
  • Your solution does exactly what I needed, thank you. Concerning your comment, the <mouse-1> still cycles between FOLDED, CHILDREN and SUBTREE; it behaves just like TAB. Commented Apr 4 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.