Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.editors    |    What? Edlin ain't good enough for you?    |    123,932 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 123,411 of 123,932    |
|    Lawrence D'Oliveiro to All    |
|    Hiding/Showing Text    |
|    29 Mar 24 00:41:10    |
   
   From: ldo@nz.invalid   
      
   Emacs has this feature called “overlays”, which let you set custom   
   display attributes for portions of a text buffer. This can include   
   completely hiding the text. That can be handy if you want to look at   
   two parts of a source file while temporarily ignoring some irrelevant   
   details in-between.   
      
   Here is a command that hides a selected region of text, replacing it   
   with a distinctive marker symbol, and also attaching a distinctive   
   category identifier for the overlay:   
      
   (defun hide_text (beg end)   
    (interactive "r")   
    (let   
    (   
    (olay (make-overlay beg end))   
    )   
    (overlay-put olay 'category 'collapsar)   
    (overlay-put olay   
    'display #("🐧\n" 0 1 (face '(:foreground "turquoise"   
   :background "yellow")))   
    )   
    (overlay-put olay 'evaporate t)   
    (deactivate-mark)   
    ) ; let   
   ) ; hide_text   
      
   Here is a function that invokes a specified callback for all overlays   
   of that category that overlap a specified position:   
      
   (defun foreach_hidden_text_at (act pos)   
    (dolist (olay (overlays-at pos))   
    (when (eq (overlay-get olay 'category) 'collapsar)   
    (funcall act olay)   
    ) ; when   
    ) ; dolist   
   ) ; foreach_hidden_text_at   
      
   And here is a command that uses foreach_hidden_text_at to reveal all   
   hidden text at the current position:   
      
   (defun reveal_text ()   
    (interactive)   
    (let   
    (   
    (revealed-something)   
    )   
    (foreach_hidden_text_at   
    (lambda (olay)   
    (delete-overlay olay)   
    (setq revealed-something t)   
    ) ; lambda   
    (point)   
    ) ; foreach_hidden_text_at   
    (unless revealed-something   
    (ding)   
    ) ; unless   
    ) ; let   
   ) ; reveal_text   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca