emacs-orgmode
[Top][All Lists]
Advanced

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

[O] modifying/deleting ovelrays; also, un-sparsifying tree?


From: Matt Price
Subject: [O] modifying/deleting ovelrays; also, un-sparsifying tree?
Date: Fri, 29 Jul 2016 10:31:46 -0400

In my gradesheets I use overlays to display the grade property in headlines -- that way I can see at a glance approximately how my students are doing:

;; still imperfect, but good enough for me. 
(defun org-grading-overlay-headings ()
  "Show grades at end of headlines that have a 'GRADE' property."
  (interactive)
  (require 'ov)

  (org-map-entries
   (lambda ()
     (when (org-entry-get (point) "GRADE")
       (ov-clear (- (line-end-position) 1)
                 (+ 0 (line-end-position)))
       (setq ov (make-overlay (- (line-end-position) 1)
                              (+ 0 (line-end-position))))
       (setq character (buffer-substring (- (line-end-position) 1) (line-end-position)))
       (overlay-put
        ov 'display
        (format  "%s  GRADE: %s CHITS: %s" character (org-entry-get (point) "GRADE") (org-entry-get (point) "CHITS")))
       (overlay-put ov 'name "grading")
       (message "%s" (overlay-get ov "name")))))
  )

This mostly works, except that I've noticed that, when I regenerate the overlays after changes, certain folded trees end up with a duplicate overlay, for reasons that I don't quite understand (maybe because the ellipses at the end of the fold interfere with my counting somehow)?
I ould like to be able to find the named overlays and remove them all at once, something like this:

(defun matt-clear-overlay ()
  (interactive)
  (let ((all-overlays (overlays-in (point-min) (point-max))))
    (dolist (x all-overlays)
      (if (string= (overlay-get x "name") "grading")
          (delete-overlay x)
          )))) ;; sorry for hanging brackets, I know it's bad form

this doesn't seem to do anything, so maybe I'm not testing right, or I'm misnderstanding overlays. In any case ,I would love to be able to locate the overlays properly, and modify or delete-and-recreate them appropriately. Can you guys help out? Just clearing all overlays is not a good option, as org seems to make heavy use of them to hide e.g. property drawers. 

An unrelated simple question: if I make a sparse tree (e.g. by searching for all subtrees with a "GRADE" property of "0" or "FAIL",), can i un-sparsify hte buffer afterwards? I didn't immediately find that option in the manual.

thanks everyone!
matt

reply via email to

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