Stefan Kangas <stefankangas@HIDDEN>
to control <at> debbugs.gnu.org
.
Full text available.Received: (at 76007) by debbugs.gnu.org; 2 Feb 2025 13:49:45 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 02 08:49:45 2025 Received: from localhost ([127.0.0.1]:33587 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1teaM5-0006uz-17 for submit <at> debbugs.gnu.org; Sun, 02 Feb 2025 08:49:45 -0500 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:58457) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>) id 1teaM3-0006uh-2O for 76007 <at> debbugs.gnu.org; Sun, 02 Feb 2025 08:49:44 -0500 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5d414b8af7bso6993036a12.0 for <76007 <at> debbugs.gnu.org>; Sun, 02 Feb 2025 05:49:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738504177; x=1739108977; darn=debbugs.gnu.org; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :from:to:cc:subject:date:message-id:reply-to; bh=xmQ4yd0t3I4qelXdctBHfLS3Eqj0FX7QWR4Q6vdzh5k=; b=L8praa+l4OY9MtU1hQ1dFDq+vHvdRthluYI0PMGmrlJvlQ8nWEYlCGV7bOQzwbcC/g fJSgtHFQ3x9szweU+EqvEGSZi5EQbAjCFE9vR4KWg4FADtR5m4q0rXCWS+1Pux0Zy2bT SIj49do7T6DBDgzlUDjdwUWg5d8eF94Ncy5y+ZotA0Q8zVCQCbZXqAjSJ6cLtkQ161ox bZ/+EjBIJsb+0pP9PVcAiUdflei4GBBXIZbDAmcaBU8eH5aQGigyHAbkjXTs9vgWTRHy P8CvQFB3iE+SKr0h2VnIL2ON+c6MdrxlThvtgCMfFK1duMlqw8ZUDrKJ5Mv+Yqida2lg Aumw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738504177; x=1739108977; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xmQ4yd0t3I4qelXdctBHfLS3Eqj0FX7QWR4Q6vdzh5k=; b=JPxRjT4DENsFT+1ZAiJVr4QlY+0RzTdsLTfvPXz1s2mH9zF3fIgBZf31VUqc1vBDF4 DGBUVCsQxDWcSZPNphEhI/DKn0HwF7c5tyiMN4GtyNr+0XhadBdQrYWTDuL3VCuUIOVI wGCLoZYhwSK3TafKAHDrdsJMQgYR7fdPUlviZbwed2RtJP832KGdBlwEE7W8hNpVLAcW NtBfxaJjmfzzHfKZFbZLPauE8+KYbwUwdiiseeIaCt+mtDAvcN+BRptBbt1ohHuZbShu zHPa4PdTOkaa0SqQxzAEjpyUrtiyn4Qxsmn3fZL6vWQuVbUPQuuKUTtG8oTfmQsoJtXG 3DaQ== X-Forwarded-Encrypted: i=1; AJvYcCUxp8SQuGAOcC62OBsbt1rX2cBmVcBzgyWs1kaOr+gp9WsQYmi3zVyI9IFFr/W2sV8DEhp5hw==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzozImVCbRDOdczwTn0uVTfWhY0NGd6lDkLHZD1cO7Khk8ioCQG zVryPdH/9pKm/43LpcIAbNWA7Y/wlJ4tBSXOikZi/SiY8TVAvpmBlrDJn9z+SDDAohbmaqPOQRH 7eP86sDNXvOV18k8SlXAy3DWGsIdRoXxjSIA= X-Gm-Gg: ASbGncu0v6jK3vvE27liI5pjX9SEXVxqa4wteK+R0PECFuho4I0zfJdUKHS9yXNYs1W BYqDisCB2Q1RGuNCpeFzzRh02W/MqhyFE6qlYgBkSB26zP84VEIOxP+7biIa3NBrjKFK8XI43jw == X-Google-Smtp-Source: AGHT+IHxRwzH84ImwGaVtCo6/RmVluGOCUn8LhwAt5EVZM4ZGzjqPl0bLQ7KPYCrP3dOdn91VEhCp30JHywzZy2V/AY= X-Received: by 2002:a05:6402:40c4:b0:5dc:893d:6dd4 with SMTP id 4fb4d7f45d1cf-5dc893d6e8emr10384478a12.0.1738504176509; Sun, 02 Feb 2025 05:49:36 -0800 (PST) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sun, 2 Feb 2025 08:49:36 -0500 From: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <m2zfj48t7f.fsf@HIDDEN> References: <m2zfj48t7f.fsf@HIDDEN> MIME-Version: 1.0 Date: Sun, 2 Feb 2025 08:49:36 -0500 X-Gm-Features: AWEUYZm2MkEWykxqtlgjTVFSDuWS9MqbNn6juPGCXBzDhkYu5c4OeOK7qf8K6To Message-ID: <CADwFkmkP5BO4eCpdu8Cc+NgZOkvBtJeKzD6fK2Eo-r6841peNw@HIDDEN> Subject: Re: bug#76007: 31.0.50; Interpreter not correctly found when using nix-shell. To: Malcolm Purvis <malcolm@HIDDEN>, 76007 <at> debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 76007 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 (-) Malcolm Purvis <malcolm@HIDDEN> writes: > In NixOS if you want to use a script that manages its own > dependencies, you use a command called "nix-shell" or "nix shell" > to launch the script. > > The start of such a script looks like: > > #! /usr/bin/env nix-shell > #! nix-shell -i bash -p imagemagick cowsay > > or > > #! /usr/bin/env nix > #! nix shell github:tomberek/-#perlWith.HTMLTokeParserSimple.LWP > --command perl -x > > The OS interpreter is nix-shell and nix-shell launches the real > interpreter to execute the rest of the script. > > With these scripts, Emacs's current behaviour is as follows: > > - nix-shell is not interpreter-mode-alist so Emacs looks at the > file's > extension: > > - If the file has an extension then the correct mode is used > - If the file does not have an extension then Fundamental mode is > used > regardless of the script's actual language. > > If the file is a shell script with the correct extension, sh-mode > is used but sh-mode fails to guess the shell, leaving the variable > sh-shell as 'nix-shell. > > In most cases this means that some shell features are not enabled, > but otherwise it is possible to edit the script. > > However, lsp-mode's bash language support (lsp-bash.el) throws an > error if sh-shell is not set to it's supported values ('sh and > 'bash), and as a result nix bash scripts fail. > > The solution is to add a new regexp to > auto-mode-interpreter-regexp that will detect a nix script and > extract the real interpreter from the second line. Nix shell can > be invoked in a number of ways but this regexp matches the common > forms. > > > diff --git a/lisp/files.el b/lisp/files.el > index 5ff40c335d7..1f3ac1431d2 100644 > --- a/lisp/files.el > +++ b/lisp/files.el > @@ -3389,6 +3389,7 @@ and `inhibit-local-variables-suffixes'. If > "\\(?:[^ \t\n]+=[^ \t\n]*[ \t]+\\)*" > "\\)?" > "\\)?" > + "\\(?:\\(?:nix\\|nix-shell\\)\n#![ > \t]+\\(?:nix\\|nix-shell\\).*\\(?:-i\\|--command\\)[ \t]+\\)?" > ;; Group 2: interpreter. "\\([^ \t\n]+\\)") > "Regexp matching interpreters, for file mode determination. > > > Malcolm Thanks for the bug report. This looks to me like a bug in lsp-mode, or lsp-bash.el. I recommend reporting the bug to them first.
bug-gnu-emacs@HIDDEN
:bug#76007
; Package emacs
.
Full text available.Received: (at submit) by debbugs.gnu.org; 2 Feb 2025 11:47:02 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 02 06:47:02 2025 Received: from localhost ([127.0.0.1]:33363 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1teYRJ-0006qJ-OT for submit <at> debbugs.gnu.org; Sun, 02 Feb 2025 06:47:02 -0500 Received: from lists.gnu.org ([2001:470:142::17]:46800) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <malcolm@HIDDEN>) id 1teYRG-0006py-KW for submit <at> debbugs.gnu.org; Sun, 02 Feb 2025 06:46:59 -0500 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 <malcolm@HIDDEN>) id 1teYRA-0001O4-V0 for bug-gnu-emacs@HIDDEN; Sun, 02 Feb 2025 06:46:53 -0500 Received: from omr-waratah-01.pc5.atmailcloud.com ([103.150.252.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <malcolm@HIDDEN>) id 1teYR9-00009y-8D for bug-gnu-emacs@HIDDEN; Sun, 02 Feb 2025 06:46:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=au-east.atmailcloud.com; s=202306; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From; bh=06SvzHBxUHWfpfbXcs7sQF7UWKuZ5Ewq+MQSqiyR6b8=; b=DB4V hlKrc9TRCxzoZFlM+ymHsx+qXbHBlaTvaT8zGD/fyf/yAGam48yxURiEoj2wB4Bxz4O5Pyy2/VYpL BXB16uzzsePr8LzFr3jsJulkLPPyTWLtw734/XIIsaNpvcV6cA958AiiL/MrR+Oa/rYRTyKsPzbnr nTmRSOFaE+dkp4tsjw6rYq+vIEggd4tDDg+l2CzRd9L5OjtmdpOCD6+akCNbeQAjaAnA01aZGCvRj rE4Bv4LPsRGjD1q3H8kw/4xC8lXLScaRoiSegOmIMkIbMoxa0HuMcbH+JPAt1R4uD5QK2TCGNoau6 rFM0gtc0eiAv6+iAKijvgKUkBirxeg==; Received: from cmr-waratah.internal.pc5.atmailcloud.com (cmr-waratah.internal.pc5.atmailcloud.com [192.168.10.1]) by omr-waratah-01.internal.pc5.atmailcloud.com (Exim/cmr-waratah.i-0641b4eba66d2f560) with ESMTPS (envelope-from <malcolm@HIDDEN>) id 1teYR4-000000001K7-2TB7 for <bug-gnu-emacs@HIDDEN>; Sun, 02 Feb 2025 11:46:46 +0000 Received: from n49-187-191-177.bla1.nsw.optusnet.com.au ([49.187.191.177] helo=lamech) by cmr-waratah.i-0641b4eba66d2f560 with esmtps (envelope-from <malcolm@HIDDEN>) id 1teYR4-000000002Xr-1Wwk for bug-gnu-emacs@HIDDEN; Sun, 02 Feb 2025 11:46:46 +0000 From: Malcolm Purvis <malcolm@HIDDEN> To: bug-gnu-emacs@HIDDEN Subject: 31.0.50; Interpreter not correctly found when using nix-shell. X-Debbugs-Cc: Date: Sun, 02 Feb 2025 22:46:44 +1100 Message-ID: <m2zfj48t7f.fsf@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; format=flowed X-atmailcloud-spam-action: no action X-Cm-Envelope: MS4xfKzVvxUIwtR6cdNOXtxtjNFyLfvGRbrJYVp71Ga5VKIHF6VcQ+6NFpahT7/4kXZR+NjuFxpOKvqRINBvQE2gSvdgox9API0/D/1KisgpqXmH6JQtPY0u zlC1sA8UIWfGmCaG6+fSFw+2gGDhxBat/26WYi4euRxsgD6kZjIUGqeYhudbgMdj8oWB6beYnP/2MA== X-Cm-Analysis: v=2.4 cv=V9F70/ni c=1 sm=1 tr=0 ts=679f5b26 cx=a_idp_f a=D4Uf56qykZ1aaY6tNX9MvQ==:117 a=D4Uf56qykZ1aaY6tNX9MvQ==:17 a=T2h4t0Lz3GQA:10 a=EEi38YYrRUig6PSkIlUA:9 X-atmailcloud-route: unknown Received-SPF: neutral client-ip=103.150.252.56; envelope-from=malcolm@HIDDEN; helo=omr-waratah-01.pc5.atmailcloud.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: submit 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: -0.3 (/) In NixOS if you want to use a script that manages its own dependencies, you use a command called "nix-shell" or "nix shell" to launch the script. The start of such a script looks like: #! /usr/bin/env nix-shell #! nix-shell -i bash -p imagemagick cowsay or #! /usr/bin/env nix #! nix shell github:tomberek/-#perlWith.HTMLTokeParserSimple.LWP --command perl -x The OS interpreter is nix-shell and nix-shell launches the real interpreter to execute the rest of the script. With these scripts, Emacs's current behaviour is as follows: - nix-shell is not interpreter-mode-alist so Emacs looks at the file's extension: - If the file has an extension then the correct mode is used - If the file does not have an extension then Fundamental mode is used regardless of the script's actual language. If the file is a shell script with the correct extension, sh-mode is used but sh-mode fails to guess the shell, leaving the variable sh-shell as 'nix-shell. In most cases this means that some shell features are not enabled, but otherwise it is possible to edit the script. However, lsp-mode's bash language support (lsp-bash.el) throws an error if sh-shell is not set to it's supported values ('sh and 'bash), and as a result nix bash scripts fail. The solution is to add a new regexp to auto-mode-interpreter-regexp that will detect a nix script and extract the real interpreter from the second line. Nix shell can be invoked in a number of ways but this regexp matches the common forms. diff --git a/lisp/files.el b/lisp/files.el index 5ff40c335d7..1f3ac1431d2 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3389,6 +3389,7 @@ and `inhibit-local-variables-suffixes'. If "\\(?:[^ \t\n]+=[^ \t\n]*[ \t]+\\)*" "\\)?" "\\)?" + "\\(?:\\(?:nix\\|nix-shell\\)\n#![ \t]+\\(?:nix\\|nix-shell\\).*\\(?:-i\\|--command\\)[ \t]+\\)?" ;; Group 2: interpreter. "\\([^ \t\n]+\\)") "Regexp matching interpreters, for file mode determination. Malcolm In GNU Emacs 31.0.50 (build 2, x86_64-apple-darwin24.2.0, NS appkit-2575.30 Version 15.2 (Build 24C101)) of 2025-01-11 built on lamechWindowing system distributor 'Apple', version 10.3.2575 System Description: macOS 15.2 Configured using: 'configure --enable-locallisppath=/usr/local/share/emacs/site-lisp --infodir=/usr/local/Cellar/emacs-head@31/31.0.50_1/share/info/emacs --prefix=/usr/local/Cellar/emacs-head@31/31.0.50_1 --without-x --without-dbus --with-native-compilation --with-imagemagick --with-modules --with-gnutls --with-rsvg --with-xml2 --with-xwidgets --with-webp --with-ns --disable-ns-self-contained 'CFLAGS=-O2 -march=native -pipe -DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT' 'LDFLAGS=-L/usr/local/lib/gcc/14 -I/usr/local/opt/gcc/include -I/usr/local/opt/libgccjit/include -I/usr/local/opt/gmp/include -I/usr/local/opt/jpeg/include'' -- Malcolm Purvis <malcolm@HIDDEN>
Malcolm Purvis <malcolm@HIDDEN>
:bug-gnu-emacs@HIDDEN
.
Full text available.bug-gnu-emacs@HIDDEN
:bug#76007
; Package emacs
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.