From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: modifying/deleting ovelrays; also, un-sparsifying tree? Date: Fri, 29 Jul 2016 10:31:46 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1149dc8e3a06d60538c71c30 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bT8pI-0007LY-Ve for emacs-orgmode@gnu.org; Fri, 29 Jul 2016 10:31:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bT8pH-0004wB-Ka for emacs-orgmode@gnu.org; Fri, 29 Jul 2016 10:31:48 -0400 Received: from mail-qk0-x233.google.com ([2607:f8b0:400d:c09::233]:33674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bT8pH-0004w6-FO for emacs-orgmode@gnu.org; Fri, 29 Jul 2016 10:31:47 -0400 Received: by mail-qk0-x233.google.com with SMTP id p74so92190693qka.0 for ; Fri, 29 Jul 2016 07:31:47 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org Mode --001a1149dc8e3a06d60538c71c30 Content-Type: text/plain; charset=UTF-8 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 --001a1149dc8e3a06d60538c71c30 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 imperf= ect, but good enough for me.=C2=A0
(defun org-grading-overlay-headings = ()
=C2=A0 "Show grades at end of headlines that have a 'GRADE&#= 39; property."
=C2=A0 (interactive)
=C2=A0 (require 'ov)
=
=C2=A0 (org-map-entries
=C2=A0=C2=A0 (lambda ()
=C2=A0=C2=A0=C2= =A0=C2=A0 (when (org-entry-get (point) "GRADE")
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (ov-clear (- (line-end-position) 1)
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (+ 0 (line-end-position)))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (setq ov (make-overlay (- (line-end-position) 1)
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 (+ 0 (line-end-position))))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 (setq character (buffer-substring (- (line-end-position) 1) (line-end-p= osition)))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (overlay-put
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ov 'display
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (format=C2=A0 "%s=C2=A0 GRADE: %s CHITS: %s&q= uot; character (org-entry-get (point) "GRADE") (org-entry-get (po= int) "CHITS")))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (overlay-= put ov 'name "grading")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 (message "%s" (overlay-get ov "name")))))
=C2=A0= )

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 be= cause the ellipses at the end of the fold interfere with my counting someho= w)?
I ould like to be able to find the named overlays and remove t= hem all at once, something like this:

(defun matt-clear-overlay ()<= br>=C2=A0 (interactive)
=C2=A0 (let ((all-overlays (overlays-in (point-m= in) (point-max))))
=C2=A0=C2=A0=C2=A0 (dolist (x all-overlays)
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (if (string=3D (overlay-get x "name") &q= uot;grading")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 (delete-overlay x)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 )))) ;; sorry for hanging brackets, I know it's bad form
this doesn't seem to do anything, so maybe I'm not test= ing right, or I'm misnderstanding overlays. In any case ,I would love t= o be able to locate the overlays properly, and modify or delete-and-recreat= e 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. prop= erty drawers.=C2=A0

An unrelated simple question: if I make a= sparse tree (e.g. by searching for all subtrees with a "GRADE" p= roperty of "0" or "FAIL",), can i un-sparsify hte buffe= r afterwards? I didn't immediately find that option in the manual.
=
thanks everyone!
matt
--001a1149dc8e3a06d60538c71c30--