From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#68487: [PATCH] Make jump commands usable for all skeletons Date: Wed, 07 Feb 2024 12:13:11 -0500 Message-ID: References: <877ckawckc.fsf@martinmarshall.com> <875xz2y46o.fsf@martinmarshall.com> <87il316y4w.fsf@martinmarshall.com> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38882"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 68487@debbugs.gnu.org To: Martin Marshall Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 07 18:14:06 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rXlUr-0009sg-8K for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Feb 2024 18:14:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXlUc-0007P9-7T; Wed, 07 Feb 2024 12:13:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rXlUb-0007P1-7j for bug-gnu-emacs@gnu.org; Wed, 07 Feb 2024 12:13:49 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rXlUa-0004TT-W7 for bug-gnu-emacs@gnu.org; Wed, 07 Feb 2024 12:13:49 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rXlUo-0003d8-7u for bug-gnu-emacs@gnu.org; Wed, 07 Feb 2024 12:14:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Feb 2024 17:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68487 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68487-submit@debbugs.gnu.org id=B68487.170732601913918 (code B ref 68487); Wed, 07 Feb 2024 17:14:02 +0000 Original-Received: (at 68487) by debbugs.gnu.org; 7 Feb 2024 17:13:39 +0000 Original-Received: from localhost ([127.0.0.1]:57808 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rXlUQ-0003cQ-TC for submit@debbugs.gnu.org; Wed, 07 Feb 2024 12:13:39 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39049) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rXlUL-0003c7-Ox for 68487@debbugs.gnu.org; Wed, 07 Feb 2024 12:13:37 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7A3BF10009F; Wed, 7 Feb 2024 12:13:13 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1707325992; bh=kLPCdqc/Ks/cnZQ90OR/1lq841SXPmMg0muwQjbTyq8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=FNPz0e84rrks3BeVC/UMwDUTnEKLhzMiXoNtzoKQMBQ+zh8gHqHRS0eMhx/HbN9oL qKfqFuCxJ9ap61hcegvyScLBEBk+8FjIsM0jR5dDs1CDreK1gH2zAsqsfipr4y7P6q cD6iWQ0SlreowM7UY++YXPXuhdFk7APUtILqA1GBDqFUEeJY7xaBq4luqN5XUHaJD1 OQkIoiyg3I8DOJMrB4WIEfBlEU9hsBAe5WLCAaHvsEUVn7o2d+mLBeeULkHemQRtMi Jb1+RZwaZ/iGhuMjX/q+ctzDly5oAIUBQ3dcka3XtuAz2riRiL1YyLV1Pf5H+y/N5f oSAk2fqsHITCg== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 676F210004C; Wed, 7 Feb 2024 12:13:12 -0500 (EST) Original-Received: from pastel (unknown [104.247.238.113]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 05144120209; Wed, 7 Feb 2024 12:13:11 -0500 (EST) In-Reply-To: <87il316y4w.fsf@martinmarshall.com> (Martin Marshall's message of "Tue, 06 Feb 2024 17:11:59 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279564 Archived-At: >>> 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