[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: New for GNU ELPA: literate-scratch
From: |
Sean Whitton |
Subject: |
Re: New for GNU ELPA: literate-scratch |
Date: |
Wed, 19 Jun 2024 10:42:50 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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.
>>
>> (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.
>> ;; 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.
--
Sean Whitton