From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Wilhelm Kirschbaum Newsgroups: gmane.emacs.bugs Subject: bug#64939: 30.0.50; The default auto-mode-interpreter-regexp does not match env with flags Date: Sat, 29 Jul 2023 23:38:07 +0200 Message-ID: <878rays89s.fsf@gmail.com> References: <87mszebgwy.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35541"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.3; emacs 30.0.50 To: 64939@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 30 00:11:41 2023 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 1qPsA1-00097u-71 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Jul 2023 00:11:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPrkG-0005yG-3V; Sat, 29 Jul 2023 17:45:04 -0400 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 1qPrkE-0005xs-Eh for bug-gnu-emacs@gnu.org; Sat, 29 Jul 2023 17:45:02 -0400 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 1qPrkE-0002v4-4e for bug-gnu-emacs@gnu.org; Sat, 29 Jul 2023 17:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qPrkD-00041b-OB for bug-gnu-emacs@gnu.org; Sat, 29 Jul 2023 17:45:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Wilhelm Kirschbaum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Jul 2023 21:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64939 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169066705415403 (code B ref -1); Sat, 29 Jul 2023 21:45:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Jul 2023 21:44:14 +0000 Original-Received: from localhost ([127.0.0.1]:49071 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qPrjS-00040N-1P for submit@debbugs.gnu.org; Sat, 29 Jul 2023 17:44:14 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:55054) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qPrjQ-000409-9s for submit@debbugs.gnu.org; Sat, 29 Jul 2023 17:44:12 -0400 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 1qPrjK-0005qh-LB for bug-gnu-emacs@gnu.org; Sat, 29 Jul 2023 17:44:06 -0400 Original-Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qPrjJ-0002k7-7I for bug-gnu-emacs@gnu.org; Sat, 29 Jul 2023 17:44:06 -0400 Original-Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fe104df822so18788135e9.1 for ; Sat, 29 Jul 2023 14:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690667043; x=1691271843; h=mime-version:message-id:in-reply-to:date:subject:to:from:user-agent :references:from:to:cc:subject:date:message-id:reply-to; bh=ClMgi5rVBG8umS11gjVntEFE195xP2hPHvyi16FmNYg=; b=KKgHBziAal2AVhqo/eH3WMxurpM4EI7lSCRMlZLxHSGLfNScXROsA2Cn3JdbeZwe/r ogEuYwIj15vb200JPyDE6lqZ1FwMAuERzZbZqridtOZYp11vdiOY5MelUjN/wfDW2b1c RZH9ofnivZ+7/Y8V658iTMY27ejLO+n7DTW2oYUk23beZxsenBfdRvBT6PRBnIyDj5gh MSTd8Ei38udsdPcoG/pDgK4N8vjGjvpIZic7Q+BOMvj2ne+8/+QDkAjmw+Fue6kEoVlV MfjK9v3IMFnihq7L6LrUBwx17REzZXDOAZV33VDjnpGHZSJurMCZ8RvKaABIjJ0nnKev wJUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690667043; x=1691271843; h=mime-version:message-id:in-reply-to:date:subject:to:from:user-agent :references:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ClMgi5rVBG8umS11gjVntEFE195xP2hPHvyi16FmNYg=; b=Eb3RdM+fu80M+aa9Ht5nnb1RUHYH+bMxGFWbWtvTHL7K4RsIpbdBFkuybqLzUqO7Sd VOxyqbP791POVNeW5JadDvjGQQwvHuKc4GrsJR/7K/owVAYUfEP3adAvXNmZqlqA26z3 mQpte+eIgFmTrnAprJ0ljT2lUefAFu0C1eSiqwaDgZ2B5VDtwPPuyxycOKRoCBScnUwp JYL5HsIiewrLtL8E6/jNbW//bBOCqjJw0AhPDiPoZyuF1UXRNDhsPqBL52GXQMujzqg3 VbOfYH12eazJQ0LmSWSu9LrHuQjFGVfkRZezKLIJnCEo0bGwU8g5CVr1VeAjBVOzV6od YydA== X-Gm-Message-State: ABy/qLaLjUmpl4+0R39fs4S7dG8Fuc6VprzsPp5L5SbJHpW6j/OeLA3F Qh3UN3we4i3DptSDFVgZGuvk6RHitf0= X-Google-Smtp-Source: APBJJlGXiCAMMtbUP144aBh8o9NQcSqg+4ax7OrMdlFCQwWm5V6P4vm+CAhL/ayB/BKmt8eEYA2AtA== X-Received: by 2002:a05:600c:2a4e:b0:3f9:b748:ff37 with SMTP id x14-20020a05600c2a4e00b003f9b748ff37mr5126529wme.20.1690667043018; Sat, 29 Jul 2023 14:44:03 -0700 (PDT) Original-Received: from melissa.local ([2c0f:ef18:1431:0:b09:9616:db04:c248]) by smtp.gmail.com with ESMTPSA id y17-20020a05600c20d100b003fba6709c68sm7311422wmm.47.2023.07.29.14.44.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jul 2023 14:44:02 -0700 (PDT) In-reply-to: <87mszebgwy.fsf@gmail.com> Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=wkirschbaum@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:266343 Archived-At: > A file without an extension will load ruby-mode if the first > line is: > > #!/usr/bin/env ruby > > but not when the first line is: > > #!/usr/bin/env -S ruby -e 'puts 123' > > Is there any reason why the latter should not be matched by the > default > `auto-mode-interpreter-regexp' value in 'files.el'? > > > A more useful example I stumbled on today while working on a > language > server after adding: > > `(add-to-list 'interpreter-mode-alist '("elixir" > . elixir-ts-mode))' > > > #!/usr/bin/env -S elixir --erl "-kernel standard_io_encoding > latin1" > > Node.start(:"next-ls-#{System.system_time()}", :shortnames) > .... > > > > Wilhelm This is a very naive solution to the above, but I am probably missing some knowledge here and will break for anyone setting the var to something custom. modified lisp/files.el @@ -3243,7 +3243,7 @@ inhibit-local-variables-p (defvar auto-mode-interpreter-regexp (purecopy "#![ \t]?\\([^ \t\n]*\ -/bin/env[ \t]\\)?\\([^ \t\n]+\\)") +/bin/env[ \t]\\)?\\(-\\{1,2\\}[a-zA-Z1-9=]+[ \t]+\\)?\\([^ \t\n]+\\)") "Regexp matching interpreters, for file mode determination. This regular expression is matched against the first line of a file to determine the file's mode in `set-auto-mode'. If it matches, the file @@ -3445,7 +3445,7 @@ set-auto-mode (setq mode (save-excursion (goto-char (point-min)) (if (looking-at auto-mode-interpreter-regexp) - (match-string 2)))) + (match-string 3)))) ;; Map interpreter name to a mode, signaling we're done at the ;; same time. (setq done (assoc-default modified lisp/progmodes/sh-script.el @@ -1481,7 +1481,7 @@ sh--guess-shell (cond ((save-excursion (goto-char (point-min)) (looking-at auto-mode-interpreter-regexp)) - (match-string 2)) + (match-string 3)) ((not buffer-file-name) sh-shell-file) ;; Checks that use `buffer-file-name' follow. ((string-match "\\.m?spec\\'" buffer-file-name) "rpm")