• Hiding/Showing Text

    From Lawrence D'Oliveiro@21:1/5 to All on Fri Mar 29 00:41:10 2024
    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: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Lawrence D'Oliveiro on Fri Mar 29 10:54:57 2024
    On 29.03.2024 01:41, Lawrence D'Oliveiro wrote:
    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.

    [...]

    I was astonished to read that there's a necessity to add such
    functions to Emacs. Would have expected that it's there already
    as Emacs being one of the prominent and widely used editors.

    If I inspect https://en.wikipedia.org/wiki/Code_folding the table
    shows three (of four) "Yes" for folding support, albeit marked
    with footnotes (which might indicate some restriction/workaround?).

    Since I'm not using that editor I'm just curious what deficiency
    the posted functions solve or add to the existing folding features
    in Emacs as seen in Wikipedia. (From the code I cannot derive that,
    so I'm asking.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johanne Fairchild@21:1/5 to Lawrence D'Oliveiro on Fri Mar 29 08:30:26 2024
    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    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.

    That's one of the fundamental objectives of literate programming. By
    the way, comp.programming.literate has been restored very recently.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Johanne Fairchild on Mon Apr 8 00:03:59 2024
    On Fri, 29 Mar 2024 08:30:26 -0300, Johanne Fairchild wrote:

    That's one of the fundamental objectives of literate programming.

    As far as I’m aware, “literate programming” is only a way of presenting code, not for letting you mess around with it. Jupyter notebooks not only
    let you present code, they also encourage experimentation. And they let
    the code itself produce rich output, like images, audio, video and even interactive widgets.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Johanne Fairchild@21:1/5 to Lawrence D'Oliveiro on Mon Apr 8 07:59:11 2024
    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    On Fri, 29 Mar 2024 08:30:26 -0300, Johanne Fairchild wrote:

    That's one of the fundamental objectives of literate programming.

    As far as I’m aware, “literate programming” is only a way of presenting code, not for letting you mess around with it.

    Literate programming allows you take entire chunks of error verification
    out of the way by replacing them with a chunk tag. (Now you look at the relevant part of your code without having to look at irrelevant parts.)
    When you want to compile your program, the literate programming tool
    replaces the chunk tag with the code to which it refers.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Axel Reichert@21:1/5 to Lawrence D'Oliveiro on Mon Apr 8 16:45:15 2024
    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    As far as I’m aware, “literate programming” is only a way of presenting code, not for letting you mess around with it. Jupyter notebooks not only
    let you present code, they also encourage experimentation. And they let
    the code itself produce rich output, like images, audio, video and even interactive widgets.

    Have a look at org-babel in Emacs.

    Axel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Johanne Fairchild on Tue Apr 9 00:45:39 2024
    On Mon, 08 Apr 2024 07:59:11 -0300, Johanne Fairchild wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    On Fri, 29 Mar 2024 08:30:26 -0300, Johanne Fairchild wrote:

    That's one of the fundamental objectives of literate programming.

    As far as I’m aware, “literate programming” is only a way of presenting
    code, not for letting you mess around with it.

    Literate programming allows you take entire chunks of error verification
    out of the way by replacing them with a chunk tag.

    Interesting, but maybe not very useful nowadays.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)