emacs-devel
[Top][All Lists]
Advanced

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

Re: New for GNU ELPA: literate-scratch


From: Philip Kaludercic
Subject: Re: New for GNU ELPA: literate-scratch
Date: Wed, 19 Jun 2024 05:44:40 +0000

Sean Whitton <spwhitton@spwhitton.name> writes:

> Hello,
>
> On Sat 15 Jun 2024 at 01:12pm GMT, Philip Kaludercic wrote:
>
>>> ;;; Code:
>>>
>>> (defun literate-scratch--extend (start end)
>>>   (save-excursion
>>>     (let ((res1
>>>        (and (goto-char start)
>>>             (not (looking-at paragraph-separate))
>>>             (and-let* ((new (car (bounds-of-thing-at-point 'paragraph))))
>>>               (and (< new start)
>>>                    (setq start new)))))
>>
>> You should be able to merge the `and-let*' and `and' like
>>
>> --8<---------------cut here---------------start------------->8---
>> (and-let* ((new (car (bounds-of-thing-at-point 'paragraph)))
>>         ((< new start)))
>>   (setq start new))
>> --8<---------------cut here---------------end--------------->8---
>
> Very interesting!
> This seems to be undocumented behaviour of the macro, though?
> I don't think I can see anything which implies it in the docstring.

Apparently so?  I thought it was documented under if-let* or when-let*,
but I couldn't find anything myself either.  BTW., an alternative is to
bind the symbol `_', which will also discard the value/bind it to a
fresh variable.

>>>
>>> (defun literate-scratch--propertize (start end)
>>>   (goto-char start)
>>>   (let ((start (1- start)))
>>>     (catch 'finish
>>>       (while t
>>>     (when-let* ((comment-start (nth 8 (syntax-ppss))))
>>
>> Could `while-let' be useful here?
>
> Don't think so, the termination test is in the middle of the loop, and
> the when-let* does not surround the entire loop body.

Ok.

>>>               ;; Examine the syntax of the paragraph's first char.
>>>               ;; If it's whitespace, we need to check the previous
>>>               ;; paragraph, to handle multiple paragraphs within a defun.
>>>               (let ((syn
>>>                      (char-syntax
>>>                       (char-after
>>>                        ;; (1+ point) unless at end-of-buf or on first line
>>>                        ;; of a paragraph beginning right at beg-of-buf.
>>>                        (and (not (eobp))
>>>                             (not (and (bobp)
>>>                                       (looking-at
>>>                                        "[[:space:]]*[^[:space:]\n]")))
>>
>> You should be able to merge this into a single `looking-at' expression
>> by matching against the beginning of a buffer (\\`).
>
> Nice, thanks.
>
>> Otherwise looks neat!
>
> Many thanks for looking.

Happy to help.

-- 
        Philip Kaludercic on peregrine



reply via email to

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