GNU logs - #64210, boring messages


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#64210: Allow ff-other-file-alist to specify which file to create
Resent-From: Aaron Zeng <azeng@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Wed, 21 Jun 2023 15:51:02 +0000
Resent-Message-ID: <handler.64210.B.16873626589313 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 64210
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: 64210 <at> debbugs.gnu.org
Cc: app-emacs-dev@HIDDEN
X-Debbugs-Original-To: bug-gnu-emacs@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.16873626589313
          (code B ref -1); Wed, 21 Jun 2023 15:51:02 +0000
Received: (at submit) by debbugs.gnu.org; 21 Jun 2023 15:50:58 +0000
Received: from localhost ([127.0.0.1]:34099 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1qC06j-0002Q9-D8
	for submit <at> debbugs.gnu.org; Wed, 21 Jun 2023 11:50:58 -0400
Received: from lists.gnu.org ([209.51.188.17]:43280)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <azeng@HIDDEN>) id 1qC06g-0002Q0-NF
 for submit <at> debbugs.gnu.org; Wed, 21 Jun 2023 11:50:55 -0400
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 <azeng@HIDDEN>)
 id 1qC06d-0006wO-Nm
 for bug-gnu-emacs@HIDDEN; Wed, 21 Jun 2023 11:50:52 -0400
Received: from mxout5.mail.janestreet.com ([64.215.233.18])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <azeng@HIDDEN>)
 id 1qC06b-0004H5-Qx
 for bug-gnu-emacs@HIDDEN; Wed, 21 Jun 2023 11:50:51 -0400
From: Aaron Zeng <azeng@HIDDEN>
Date: Wed, 21 Jun 2023 11:50:46 -0400
Message-ID: <q7mwmzw6ch5.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=64.215.233.18; envelope-from=azeng@HIDDEN;
 helo=mxout5.mail.janestreet.com
X-Spam_score_int: -18
X-Spam_score: -1.9
X-Spam_bar: -
X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.4 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.4 (--)

--=-=-=
Content-Type: text/plain

Tags: patch

Tags: patch


This patch adds an optional third element to the lists that make
ff-other-file-alist.  If this third element is present, it is used as
the extension for a new file, when none of the other options were
found.  Previously, this was forced to be the first extension in the
list, which unnecessarily coupled search order and file-to-create.

The specific use case I have in mind is for the following scenario in
OCaml source files: it is common to have the following three files for
a module "Foo": foo.ml, foo.mli, and foo_intf.ml.  I would like to
make ff-find-other-file cycle between these files if all of them
exist, or to create a new file if they do not.  However, it is also
normal for only foo.ml and foo.mli to exist, and foo_intf.ml should
not be created if it is not necessary.

At the moment, if the user is looking at foo.mli, there is no way to
program ff-other-file-alist to say, "go to foo_intf.ml if it exists,
otherwise foo.ml, but if neither exist, create foo.ml".  This patch
makes it possible to specify what file to create, if it is not the
first file searched for.

The manual has not yet been updated for this change, since I wanted to
get some feedback on the patch itself first.  Happy to make the
changes in the appropriate places if the patch looks reasonable.

In GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars)
 of 2023-02-09 built on igm-qws-u12685a
Repository revision: 739b5d0e52d83ec567bd61a5a49ac0e93e0eb469
Repository branch: HEAD
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: CentOS Linux 7 (Core)

Configured using:
 'configure --with-x-toolkit=lucid --without-gpm --without-gconf
 --without-selinux --without-imagemagick --with-modules --with-gif=no
 --with-cairo --with-rsvg
 --prefix=/j/office/app/emacs/builds/28.2-20230209-135825'


--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
 filename=0001-Allow-ff-other-file-alist-functions-to-be-lambdas.patch

From 6aba92d369183035cd86cc56bea5104dfc1816d4 Mon Sep 17 00:00:00 2001
From: "Aaron L. Zeng" <azeng@HIDDEN>
Date: Mon, 12 Jun 2023 18:43:38 -0400
Subject: [PATCH 1/2] Allow ff-other-file-alist functions to be lambdas

* lisp/find-file.el (ff-other-file-alist, ff-find-the-other-file):
allow functions in the alist to be lambdas, by just checking
`functionp'.  Also make a minor docstring correction to
`ff-other-file-alist'.
---
 lisp/find-file.el | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lisp/find-file.el b/lisp/find-file.el
index 05459c3643d..e4c86ecdfee 100644
--- a/lisp/find-file.el
+++ b/lisp/find-file.el
@@ -215,10 +215,10 @@ matching extension or name (e.g., `.cc' yields `.hh').
 
 This alist should be set by the major mode.
 
-Note: if an element of the alist names a FUNCTION as its cdr, that
-function must return a non-nil list of file-names.  It cannot
-return nil, nor can it signal in any way a failure to find a suitable
-list of file names."
+Note: if an element of the alist names a FUNCTION as its cadr,
+that function must return a non-nil list of file-names.  It
+cannot return nil, nor can it signal in any way a failure to find
+a suitable list of file names."
   :type '(choice (repeat (list regexp (choice (repeat string) function)))
 		 symbol))
 
@@ -469,7 +469,7 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
 
         ;; if we have a function to generate new names,
         ;; invoke it with the name of the current file
-        (if (and (atom action) (fboundp action))
+        (if (functionp action)
             (setq suffixes (funcall action (ff-buffer-file-name))
                   match (cons (car match) (list suffixes))
                   stub nil
-- 
2.39.3


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0002-Allow-ff-other-file-alist-to-specify-the-extension-f.patch

From 13d1881e03ea838c5448da6b57678c7ba4c48704 Mon Sep 17 00:00:00 2001
From: "Aaron L. Zeng" <azeng@HIDDEN>
Date: Tue, 13 Jun 2023 17:07:40 -0400
Subject: [PATCH 2/2] Allow ff-other-file-alist to specify the extension for a
 new file

* lisp/find-file.el (ff-other-file-alist, ff-find-the-other-file): Add
an optional third element to the lists that make ff-other-file-alist.
If this third element is present, it is used as the extension for a
new file, when none of the other options were found.  Previously, this
was forced to be the first extension in the list, which unnecessarily
coupled search order and file-to-create.
---
 lisp/find-file.el | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/lisp/find-file.el b/lisp/find-file.el
index e4c86ecdfee..807f46e637c 100644
--- a/lisp/find-file.el
+++ b/lisp/find-file.el
@@ -192,7 +192,7 @@ filename that EXTRACT returned."
 The value could be an alist or a symbol whose value is an alist.
 Each element of the alist has the form
 
-   (REGEXP (EXTENSION...))
+   (REGEXP (EXTENSION...) [CREATE-EXTENSION])
 
 where REGEXP is the regular expression matching a file's extension,
 and EXTENSIONs is the list of literal file-name extensions to search
@@ -202,7 +202,7 @@ through each directory specified in `ff-search-directories'.
 
 Alist elements can also be of the form
 
-   (REGEXP FUNCTION)
+   (REGEXP FUNCTION [CREATE-EXTENSION])
 
 where FUNCTION is a function of one argument, the current file's name,
 that returns the list of possible names of the corresponding files, with
@@ -210,8 +210,11 @@ or without leading directories.  Note the difference: FUNCTION returns
 the list of file names, not their extensions.  This is for the case when
 REGEXP is not enough to determine the file name of the other file.
 
-If a file is not found, a new one is created with the first
-matching extension or name (e.g., `.cc' yields `.hh').
+If a file is not found, a new one is created with the first matching
+extension or name (e.g., `.cc' yields `.hh').  If [CREATE-EXTENSION]
+is present, it is used instead of the first extension.  If
+[CREATE-EXTENSION] is a function, it is called with a single argument,
+the current file's name, and the name it returns is used instead.
 
 This alist should be set by the major mode.
 
@@ -219,7 +222,13 @@ Note: if an element of the alist names a FUNCTION as its cadr,
 that function must return a non-nil list of file-names.  It
 cannot return nil, nor can it signal in any way a failure to find
 a suitable list of file names."
-  :type '(choice (repeat (list regexp (choice (repeat string) function)))
+  :type '(choice (repeat (list regexp
+                               (choice :tag "Extensions to try"
+                                       (repeat string)
+                                       function)
+                               (choice :tag "Extension to create"
+                                       (list :inline t :tag "string" string)
+                                       (list :inline t :tag "function" function))))
 		 symbol))
 
 (defcustom ff-search-directories 'cc-search-directories
@@ -465,7 +474,11 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
         ;; otherwise, suffixes contains what we need
         (setq suffixes (car (cdr match))
               action (car (cdr match))
-              found nil)
+              found nil
+              default-name (caddr match))
+
+        (when (functionp default-name)
+          (setq default-name (funcall default-name (ff-buffer-file-name))))
 
         ;; if we have a function to generate new names,
         ;; invoke it with the name of the current file
@@ -473,7 +486,7 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
             (setq suffixes (funcall action (ff-buffer-file-name))
                   match (cons (car match) (list suffixes))
                   stub nil
-                  default-name (car suffixes))
+                  default-name (or default-name (car suffixes)))
 
           ;; otherwise build our filename stub
           (cond
@@ -493,7 +506,7 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
 
           ;; if we find nothing, we should try to get a file like this one
           (setq default-name
-                (concat stub (car (car (cdr match))))))
+                (concat stub (or default-name (car (car (cdr match)))))))
 
         ;; do the real work - find the file
         (setq found
-- 
2.39.3


--=-=-=--




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Aaron Zeng <azeng@HIDDEN>
Subject: bug#64210: Acknowledgement (Allow ff-other-file-alist to specify
 which file to create)
Message-ID: <handler.64210.B.16873626589313.ack <at> debbugs.gnu.org>
References: <q7mwmzw6ch5.fsf@HIDDEN>
X-Gnu-PR-Message: ack 64210
X-Gnu-PR-Package: emacs
X-Gnu-PR-Keywords: patch
Reply-To: 64210 <at> debbugs.gnu.org
Date: Wed, 21 Jun 2023 15:51:02 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 bug-gnu-emacs@HIDDEN

If you wish to submit further information on this problem, please
send it to 64210 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
64210: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D64210
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message received at control <at> debbugs.gnu.org:


Received: (at control) by debbugs.gnu.org; 3 Sep 2023 11:49:33 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Sep 03 07:49:33 2023
Received: from localhost ([127.0.0.1]:39865 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1qclbh-0004lO-Hp
	for submit <at> debbugs.gnu.org; Sun, 03 Sep 2023 07:49:33 -0400
Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]:62946)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <stefankangas@HIDDEN>) id 1qclbf-0004l8-Et
 for control <at> debbugs.gnu.org; Sun, 03 Sep 2023 07:49:31 -0400
Received: by mail-lj1-x22a.google.com with SMTP id
 38308e7fff4ca-2bcda0aaf47so16816981fa.1
 for <control <at> debbugs.gnu.org>; Sun, 03 Sep 2023 04:49:20 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20221208; t=1693741755; x=1694346555; darn=debbugs.gnu.org;
 h=to:subject:message-id:date:mime-version:from:from:to:cc:subject
 :date:message-id:reply-to;
 bh=VRoDw49VbXblfOKoTElPtLKXC9aFF0luXrvGFAGU+fQ=;
 b=iD9PDGgnbdFmD4+bjkErLAyi90gJKPQAf/h9MyG0t0HCEqhJ3LZpxUy91SRRMTCKF2
 376/ZwpolvDWoryusJUnQBE/U70uMtHGoIpsDfGDxrS2t3OvfWFtB1gWNSs/ru2FIrTS
 4FAbofgcK1Je1LQRD9ivD55ImI7cuDpwy5hwWTN0NIJ6PWkqjQCzgJbpaNao42fJ9ESO
 kCw278Kpq0LmqJIFVBmFeA7I90Uvh0OTgwd5QlxpLpkC8Uwr2fARu4T7w7jJwTbVNUii
 bwxkd5GdrcPnL5QAdgqErjtOxoJ6hKS3O3wD0/MjEnmqwI656VeJMvFh9/9xbgf1u2Ey
 ZelA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20221208; t=1693741755; x=1694346555;
 h=to:subject:message-id:date:mime-version:from:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=VRoDw49VbXblfOKoTElPtLKXC9aFF0luXrvGFAGU+fQ=;
 b=g/X2i+GAl0JM47p9jzZmCbkQCetSk3mV3aB/KIWf24oIRUB40ynyeQbJn0CLizMsxv
 s+JnHgSXQA0AClZKZw+aBVtudnC5fTQReP8xrpE/Smk+OQn/hE8F6sMxP4eM+DkGRQcK
 SmQYH/3QAoIZ/PRmJG6TpzfdDs117eYSXPAekeGtBJ0cfjD7WHzcMf8L9iiDJuMwL/T4
 yZ6oWwUWAS2TXkbq64qKXnby+HP2ofyO6iJ8Rl/J41nSxqSmfHTPxzK2fjst2f+QLNrW
 23OtK+Hoc70PNOsP9lh8pJ0wHml88ljRKHkj/OuBLjWjMxI/Zbh1ikZnvKMyWXlP916k
 OyWg==
X-Gm-Message-State: AOJu0YwY3r9t2v2HstkGseWWmkZO9ubPucNwkEFPDNTlJQX07AhvAwL/
 jBosHV/JgAz8FqirEZJ2cYslBbPfR1kE4InTaUFTaSczvwg=
X-Google-Smtp-Source: AGHT+IH1G1Ty6+ZULRTQ3q71fn0dsrOIODhlbAolOhCZev+iA1nYdba01Kuq/udSoMRcqlXvx4Ya1OVzpqCqeOYTJU4=
X-Received: by 2002:a05:6512:31c6:b0:4f9:dac6:2f3d with SMTP id
 j6-20020a05651231c600b004f9dac62f3dmr2742465lfe.13.1693741754960; Sun, 03 Sep
 2023 04:49:14 -0700 (PDT)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Sun, 3 Sep 2023 04:49:14 -0700
From: Stefan Kangas <stefankangas@HIDDEN>
MIME-Version: 1.0
Date: Sun, 3 Sep 2023 04:49:14 -0700
Message-ID: <CADwFkmnyv6bC_suR59siEqb5Oh+vAeGayEdc-yc0QnYsadSPJA@HIDDEN>
Subject: control message for bug #64210
To: control <at> debbugs.gnu.org
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: control
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

severity 64210 wishlist
quit





Last modified: Sun, 3 Sep 2023 12:00:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.