emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* modifying/deleting ovelrays; also, un-sparsifying tree?
@ 2016-07-29 14:31 Matt Price
  2016-07-29 14:46 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Price @ 2016-07-29 14:31 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 2237 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2779 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-29 22:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-29 14:31 modifying/deleting ovelrays; also, un-sparsifying tree? Matt Price
2016-07-29 14:46 ` Nicolas Goaziou
2016-07-29 15:31   ` Matt Price
2016-07-29 16:21     ` Matt Price
2016-07-29 22:31       ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).