From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Martin Marshall <law@martinmarshall.com>
Cc: 68487@debbugs.gnu.org
Subject: bug#68487: [PATCH] Make jump commands usable for all skeletons
Date: Wed, 07 Feb 2024 12:13:11 -0500 [thread overview]
Message-ID: <jwvy1bws07s.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87il316y4w.fsf@martinmarshall.com> (Martin Marshall's message of "Tue, 06 Feb 2024 17:11:59 -0500")
>>> There's one problem though. The autoloaded keybindings for
>>> `expand-jump-to-next-slot' and `expand-jump-to-previous-slot' won't work
>>> the first time they're called on an expanded skeleton, unless the user
>>> has previously loaded expand.el.
>>
>> Hmm... this suggests we should try and "merge" `expand-list/pos` and
>> `skeleton-positions`?
>
> My thinking was just to initialize `expand-list/pos/index` in skeleton.el, so
> that a skeleton-command could populate `expand-pos` with locations from
> `skeleton-positions` even before expand.el has loaded.
I'm having trouble understanding the design behind `expand.el`, but IIUC
`expand-list` is basically the variable through which interaction with
other things is expected to take place, so I think it's fair to make
`skeleton.el` set `expand-list` whereas `expand-pos/index` seem like
internal vars and `skeleton.el` shouldn't touch them.
But the docstring of `expand-list` needs to be (re)written for that, first.
Ideally this should go along with the removal of the use of a vector in
`expand-list`, which not only is odd given its name but is odd because
it seems completely useless. IOW my reading of the code suggests the
code would work just as well with the patch below.
Stefan
diff --git a/lisp/expand.el b/lisp/expand.el
index f32ab101224..714cc5fc11a 100644
--- a/lisp/expand.el
+++ b/lisp/expand.el
@@ -337,17 +337,12 @@ expand-abbrev-hook
(progn
;; expand-point tells us if we have inserted the text
;; ourself or if it is the hook which has done the job.
+ (if (listp expand-list)
+ (setq expand-index 0
+ expand-pos (expand-list-to-markers expand-list)
+ expand-list nil))
(if expand-point
- (progn
- (if (vectorp expand-list)
- (expand-build-marks expand-point))
- (indent-region p expand-point nil))
- ;; an outside function can set expand-list to a list of
- ;; markers in reverse order.
- (if (listp expand-list)
- (setq expand-index 0
- expand-pos (expand-list-to-markers expand-list)
- expand-list nil)))
+ (indent-region p expand-point nil))
(run-hooks 'expand-expand-hook)
t)
nil))
@@ -359,12 +354,16 @@ expand-do-expansion
(text (aref vect 0))
(position (aref vect 1))
(jump-args (aref vect 2))
- (hook (aref vect 3)))
+ (hook (aref vect 3))
+ (startpos (point)))
(cond (text
(insert text)
(setq expand-point (point))))
(if jump-args
- (funcall #'expand-build-list (car jump-args) (cdr jump-args)))
+ (setq expand-list (nreverse
+ (mapcar (lambda (offset)
+ (+ startpos -1 offset))
+ (cdr jump-args)))))
(if position
(backward-char position))
(if hook
@@ -415,28 +414,6 @@ expand-jump-to-next-slot
;;;###autoload (define-key abbrev-map "p" 'expand-jump-to-previous-slot)
;;;###autoload (define-key abbrev-map "n" 'expand-jump-to-next-slot)
-(defun expand-build-list (len l)
- "Build a vector of offset positions from the list of positions."
- (expand-clear-markers)
- (setq expand-list (vconcat l))
- (let ((i 0)
- (lenlist (length expand-list)))
- (while (< i lenlist)
- (aset expand-list i (- len (1- (aref expand-list i))))
- (setq i (1+ i)))))
-
-(defun expand-build-marks (p)
- "Transform the offsets vector into a marker vector."
- (if expand-list
- (progn
- (setq expand-index 0)
- (setq expand-pos (make-vector (length expand-list) nil))
- (let ((i (1- (length expand-list))))
- (while (>= i 0)
- (aset expand-pos i (copy-marker (- p (aref expand-list i))))
- (setq i (1- i))))
- (setq expand-list nil))))
-
(defun expand-clear-markers ()
"Make the markers point nowhere."
(if expand-pos
next prev parent reply other threads:[~2024-02-07 17:13 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-15 20:45 bug#68487: [PATCH] Make jump commands usable for all skeletons Martin Marshall
2024-01-27 9:13 ` Eli Zaretskii
2024-01-27 18:27 ` Martin Marshall
2024-01-27 18:51 ` Eli Zaretskii
2024-01-27 21:48 ` Martin Marshall
2024-01-28 5:52 ` Eli Zaretskii
2024-01-28 18:47 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-28 19:24 ` Eli Zaretskii
2024-01-28 19:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-05 21:46 ` Martin Marshall
2024-02-06 2:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-06 22:11 ` Martin Marshall
2024-02-07 17:13 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-02-26 1:26 ` Martin Marshall
2024-03-03 4:07 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-14 7:50 ` Eli Zaretskii
2024-03-22 0:05 ` martin
2024-04-06 8:56 ` Eli Zaretskii
2024-04-18 8:58 ` Eli Zaretskii
2024-05-02 8:37 ` Eli Zaretskii
2024-05-18 8:28 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvy1bws07s.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=68487@debbugs.gnu.org \
--cc=law@martinmarshall.com \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.