Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight current subtree in emacs org-mode?

Tags:

emacs

org-mode

How can I make the current subtree more clearly recognizable?

Making the "line-number" bold is ok, or just underlining the whole text of the current subtree would be also good.

I mean, can some one help to give me some elisp code? to achieve this (underlining the whole subtreee, for example)?


I can't show you underline, so I bold the example :

* [1] this is a subtree

some text

** [1.1] subtree n°2

and text too

*** [1.1.1]subtree hello

** [2] have a nice day

like image 893
ryrd Avatar asked Oct 15 '12 06:10

ryrd


1 Answers

Load the following definitions

(defun org-subtree-highlight-find-overlay (p1 p2)
  "Find an overlay with property 'org-subtree-highlight-overlay"
  (defun org-subtree-highlight-find-overlay01 (overlays)
    (if overlays
    (let ((ov (car overlays)))
      (if (overlay-get ov 'org-subtree-highlight-overlay)
          ov
        (org-subtree-highlight-find-overlay01 (cdr overlays))))
      nil))
  (org-subtree-highlight-find-overlay01 (overlays-in p1 p2)))

(defun org-subtree-highlight-toggle ()
  "Toggle subtree highlighting"
  (interactive)
  (save-excursion
    (let* ((p1 (progn (org-back-to-heading t) (point)))
       (p2 (progn (outline-next-visible-heading 1)
              (if (and (org-at-heading-p) (not (eobp))) (backward-char 1))
              (point)))
       (ov (org-subtree-highlight-find-overlay p1 p2)))
      (if ov
      (delete-overlay ov)
    (setq ov (make-overlay p1 p2))
    (overlay-put ov 'org-subtree-highlight-overlay t)
    ;; set a format for the subtree (can be also 'bold)
    (overlay-put ov 'font-lock-face 'underline)))))

;; keybindin example
(add-hook 'org-mode-hook
      (lambda ()
        (local-set-key "\C-c\C-h" 'org-subtree-highlight-toggle)))

The result should be like this

emacs screenshot

like image 130
slitvinov Avatar answered Oct 14 '22 13:10

slitvinov