emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Major mode of orgweb/publish.sh?
@ 2023-04-14  7:49 Ruijie Yu via General discussions about Org-mode.
  2023-04-14  8:11 ` Ruijie Yu via General discussions about Org-mode.
  2023-04-14  8:20 ` Ihor Radchenko
  0 siblings, 2 replies; 11+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-14  7:49 UTC (permalink / raw)
  To: Emacs orgmode

Hello,

What is the expected major mode for orgweb/publish.sh?  When I open it,
I see it is in `shell-script-mode'.  This is what I see in
orgweb/publish.sh:

--8<---------------cut here---------------start------------->8---
#!/usr/bin/env sh

":" ; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
...
--8<---------------cut here---------------end--------------->8---

When I remove the empty line 2 and run `normal-mode', the file now opens
in `emacs-lisp-mode'.  I have a sneaking suspicion that
`emacs-lisp-mode' is the expected major mode for this file, because
there is also the `lexical-binding' variable declaration on the property
line, which has no effects when the major mode is shell.

-- 
Best,


RY


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  7:49 Major mode of orgweb/publish.sh? Ruijie Yu via General discussions about Org-mode.
@ 2023-04-14  8:11 ` Ruijie Yu via General discussions about Org-mode.
  2023-04-14  8:15   ` Ruijie Yu via General discussions about Org-mode.
  2023-04-14  8:20 ` Ihor Radchenko
  1 sibling, 1 reply; 11+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-14  8:11 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: emacs-orgmode


Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org> writes:

> Hello,
>
> What is the expected major mode for orgweb/publish.sh?  When I open it,
> I see it is in `shell-script-mode'.  This is what I see in
> orgweb/publish.sh:
>
> --8<---------------cut here---------------start------------->8---
> #!/usr/bin/env sh
>
> ":" ; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
> ...
> --8<---------------cut here---------------end--------------->8---
>
> When I remove the empty line 2 and run `normal-mode', the file now opens
> in `emacs-lisp-mode'.  I have a sneaking suspicion that
> `emacs-lisp-mode' is the expected major mode for this file, because
> there is also the `lexical-binding' variable declaration on the property
> line, which has no effects when the major mode is shell.

In case I am right, I'll send a patch for this and another issue I find
for review shortly.

-- 
Best,


RY


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  8:11 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-14  8:15   ` Ruijie Yu via General discussions about Org-mode.
  2023-04-14  8:28     ` Ihor Radchenko
  0 siblings, 1 reply; 11+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-14  8:15 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1046 bytes --]


Ruijie Yu <ruijie@netyu.xyz> writes:

>> Hello,
>>
>> What is the expected major mode for orgweb/publish.sh?  When I open it,
>> I see it is in `shell-script-mode'.  This is what I see in
>> orgweb/publish.sh:
>>
>> --8<---------------cut here---------------start------------->8---
>> #!/usr/bin/env sh
>>
>> ":" ; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
>> ...
>> --8<---------------cut here---------------end--------------->8---
>>
>> When I remove the empty line 2 and run `normal-mode', the file now opens
>> in `emacs-lisp-mode'.  I have a sneaking suspicion that
>> `emacs-lisp-mode' is the expected major mode for this file, because
>> there is also the `lexical-binding' variable declaration on the property
>> line, which has no effects when the major mode is shell.
>
> In case I am right, I'll send a patch for this and another issue I find
> for review shortly.

Here attached is the patch for orgweb.  The commit message describes the
two issues I find regarding orgweb/publish.sh.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-publish.sh-fixed-major-mode-converted-load-into-requ.patch --]
[-- Type: text/x-patch, Size: 1395 bytes --]

From 90fd8ecc39cb279ee27e0db2f637f60c7b80af07 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie@netyu.xyz>
Date: Fri, 14 Apr 2023 16:04:27 +0800
Subject: [PATCH] * publish.sh: fixed major mode; converted load into require

Major mode was erronously set to shell-script-mode because of the empty line.

Converted the `load' into `require' because it allows someone working on a local
repo to `eval-buffer' successfully, given that the individual installs these
dependencies from GNU/NonGNU Elpa.  Previously, due to the hard-coded path,
`eval-buffer' would not be successful.
---
 publish.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/publish.sh b/publish.sh
index f756ff6..b3911d2 100755
--- a/publish.sh
+++ b/publish.sh
@@ -1,13 +1,13 @@
 #!/usr/bin/env sh
-
-":"; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
+":" ; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
 
 (add-to-list 'load-path "~/org-mode/lisp/")
 (add-to-list 'load-path "~/org-contrib/lisp/")
 (require 'ox-html)
 (require 'ox-extra)
 (ox-extras-activate '(ignore-headlines))
-(load "/usr/share/emacs/site-lisp/elpa-src/htmlize-1.56/htmlize.el")
+(add-to-list 'load-path "/usr/share/emacs/site-lisp/elpa-src/htmlize-1.56")
+(require 'htmlize)
 
 (setq make-backup-files nil
       debug-on-error t)
-- 
2.40.0


[-- Attachment #3: Type: text/plain, Size: 16 bytes --]


-- 
Best,


RY

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  8:20 ` Ihor Radchenko
@ 2023-04-14  8:19   ` Ruijie Yu via General discussions about Org-mode.
  2023-04-14  8:54     ` Ihor Radchenko
  0 siblings, 1 reply; 11+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-14  8:19 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Emacs orgmode


Ihor Radchenko <yantar92@posteo.net> writes:

> Ruijie Yu via "General discussions about Org-mode."
> <emacs-orgmode@gnu.org> writes:
>
>> What is the expected major mode for orgweb/publish.sh?  When I open it,
>> I see it is in `shell-script-mode'.  This is what I see in
>> orgweb/publish.sh:
>>
>> --8<---------------cut here---------------start------------->8---
>> #!/usr/bin/env sh
>>
>> ":" ; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
>> ...
>
> The mode is technically shell-script. The file is using shell script
> magic to write foreign language (Elisp) script inline.
>
>> When I remove the empty line 2 and run `normal-mode', the file now opens
>> in `emacs-lisp-mode'.  I have a sneaking suspicion that
>> `emacs-lisp-mode' is the expected major mode for this file, because
>> there is also the `lexical-binding' variable declaration on the property
>> line, which has no effects when the major mode is shell.
>
> You can do either way, depending on which part of the script you want to edit.

I tried to actually compare the two versions, and found out that the
lexical-binding does nothing at all during the script execution,
regardless of whether there is an empty line or not.  Is this a bug or
an expected behavior?

FTR, when opening the file in a buffer, the property line in a file
without empty line is properly recognized, whereas in the file with
empty line it is not recognized.

-- 
Best,


RY


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  7:49 Major mode of orgweb/publish.sh? Ruijie Yu via General discussions about Org-mode.
  2023-04-14  8:11 ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-14  8:20 ` Ihor Radchenko
  2023-04-14  8:19   ` Ruijie Yu via General discussions about Org-mode.
  1 sibling, 1 reply; 11+ messages in thread
From: Ihor Radchenko @ 2023-04-14  8:20 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Emacs orgmode

Ruijie Yu via "General discussions about Org-mode."
<emacs-orgmode@gnu.org> writes:

> What is the expected major mode for orgweb/publish.sh?  When I open it,
> I see it is in `shell-script-mode'.  This is what I see in
> orgweb/publish.sh:
>
> --8<---------------cut here---------------start------------->8---
> #!/usr/bin/env sh
>
> ":" ; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
> ...

The mode is technically shell-script. The file is using shell script
magic to write foreign language (Elisp) script inline.

> When I remove the empty line 2 and run `normal-mode', the file now opens
> in `emacs-lisp-mode'.  I have a sneaking suspicion that
> `emacs-lisp-mode' is the expected major mode for this file, because
> there is also the `lexical-binding' variable declaration on the property
> line, which has no effects when the major mode is shell.

You can do either way, depending on which part of the script you want to edit.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  8:15   ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-14  8:28     ` Ihor Radchenko
  2023-04-14  9:20       ` Ruijie Yu via General discussions about Org-mode.
  2023-04-19  9:49       ` Bastien Guerry
  0 siblings, 2 replies; 11+ messages in thread
From: Ihor Radchenko @ 2023-04-14  8:28 UTC (permalink / raw)
  To: Ruijie Yu via General discussions about Org-mode.; +Cc: Ruijie Yu, Bastien

Ruijie Yu via "General discussions about Org-mode."
<emacs-orgmode@gnu.org> writes:

> Major mode was erronously set to shell-script-mode because of the empty line.

There is no error there. The line in question is inline stdin redirect
in shell. "#..." is what is fed to exec emacs. There is no intention to
define mode for publish.sh there, just a standard Elisp script header.

> Converted the `load' into `require' because it allows someone working on a local
> repo to `eval-buffer' successfully, given that the individual installs these
> dependencies from GNU/NonGNU Elpa.  Previously, due to the hard-coded path,
> `eval-buffer' would not be successful.

Looks reasonable, but I will let Bastien decide on this. He is the
author of this file.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  8:19   ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-14  8:54     ` Ihor Radchenko
  0 siblings, 0 replies; 11+ messages in thread
From: Ihor Radchenko @ 2023-04-14  8:54 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Emacs orgmode

Ruijie Yu <ruijie@netyu.xyz> writes:

>> You can do either way, depending on which part of the script you want to edit.
>
> I tried to actually compare the two versions, and found out that the
> lexical-binding does nothing at all during the script execution,
> regardless of whether there is an empty line or not.  Is this a bug or
> an expected behavior?

I suspect that lexical binding is used there just as a good measure for
future compatibility - current Elisp standards promote using lexical
binding unless the opposite is strictly necessary.

> FTR, when opening the file in a buffer, the property line in a file
> without empty line is properly recognized, whereas in the file with
> empty line it is not recognized.

This is Emacs subtlety. We are using what looks like Emacs property line
close to the beginning of the buffer without actual intention to tell
Emacs anything. I do not see why we should care much though.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  8:28     ` Ihor Radchenko
@ 2023-04-14  9:20       ` Ruijie Yu via General discussions about Org-mode.
  2023-04-19 16:54         ` Max Nikulin
  2023-04-19  9:49       ` Bastien Guerry
  1 sibling, 1 reply; 11+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-14  9:20 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Bastien, emacs-orgmode


Ihor Radchenko <yantar92@posteo.net> writes:

> Ruijie Yu via "General discussions about Org-mode."
> <emacs-orgmode@gnu.org> writes:
>
>> Major mode was erronously set to shell-script-mode because of the empty line.
>
> There is no error there. The line in question is inline stdin redirect
> in shell. "#..." is what is fed to exec emacs. There is no intention to
> define mode for publish.sh there, just a standard Elisp script header.

Instead of "inline stdin redirect", this instead just passes Emacs the
file name and Emacs just reads from the file again.

I was about to propose changing the shbang line into just
#!/usr/bin/emacs -x, but even though the --help text says this is
exactly the case to use it, running such a script opens up a graphical
terminal which is unexpected.

But regardless, I don't quite care about it as long as it does its job
(other than the fact that I need to `M-x emacs-lisp-mode RET' at its
current state, and the concern that the lexical binding property line
takes effect neither in-buffer nor during script execution), so I'll let
you or Bastien decide whether doing anything about the first few lines
is worth it.

>> Converted the `load' into `require' because it allows someone working on a local
>> repo to `eval-buffer' successfully, given that the individual installs these
>> dependencies from GNU/NonGNU Elpa.  Previously, due to the hard-coded path,
>> `eval-buffer' would not be successful.
>
> Looks reasonable, but I will let Bastien decide on this. He is the
> author of this file.

Sounds good.  Let's wait for that, along with his confirmation that my
copyright process is complete.

-- 
Best,


RY


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  8:28     ` Ihor Radchenko
  2023-04-14  9:20       ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-19  9:49       ` Bastien Guerry
  2023-04-21  3:09         ` Ruijie Yu via General discussions about Org-mode.
  1 sibling, 1 reply; 11+ messages in thread
From: Bastien Guerry @ 2023-04-19  9:49 UTC (permalink / raw)
  To: Ihor Radchenko
  Cc: Ruijie Yu via General discussions about Org-mode., Ruijie Yu

Ihor Radchenko <yantar92@posteo.net> writes:

>> Converted the `load' into `require' because it allows someone working on a local
>> repo to `eval-buffer' successfully, given that the individual installs these
>> dependencies from GNU/NonGNU Elpa.  Previously, due to the hard-coded path,
>> `eval-buffer' would not be successful.
>
> Looks reasonable, but I will let Bastien decide on this. He is the
> author of this file.

LGTM too!  Please go ahead, thanks,

-- 
 Bastien Guerry


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-14  9:20       ` Ruijie Yu via General discussions about Org-mode.
@ 2023-04-19 16:54         ` Max Nikulin
  0 siblings, 0 replies; 11+ messages in thread
From: Max Nikulin @ 2023-04-19 16:54 UTC (permalink / raw)
  To: emacs-orgmode

On 14/04/2023 16:20, Ruijie Yu wrote:
> Ihor Radchenko writes:
>> Ruijie Yu writes:
>>> Major mode was erronously set to shell-script-mode because of the empty line.

Empty line was added by mistake, see "23.3 Choosing File Modes" in the 
Emacs manual:
(info "(emacs) Choosing Modes")
https://www.gnu.org/software/emacs/manual/html_node/emacs/Choosing-Modes.html
----
When the first line starts with ‘#!’, you usually cannot use the ‘-*-’
feature on the first line, because the system would get confused when
running the interpreter. So Emacs looks for ‘-*-’ on the second line in
such files as well as on the first line. The same is true for man pages
which start with the magic string ‘'\"’ to specify a list of troff
preprocessors.
----

>> The line in question is inline stdin redirect
>> in shell. "#..." is what is fed to exec emacs.

There is no stdin redirection,
":"; exec emacs --script "$0" #...
line instructs shell to stop interpreting this file and to execute emacs 
instead, passing file name for this script. This line is valid for both 
shell (sequence of "true" and "exec" commands) and elisp (string and 
comment). So this is a valid elisp file for emacs.

> I was about to propose changing the shbang line into just
> #!/usr/bin/emacs -x

It would fix path to emacs binary. Currently double trampoline is used. 
I see no point in /usr/bin/env since location of shell is considered 
fixed. That is why

#!/bin/sh

should work as well. Shell looks up for emacs in the $PATH environment 
variable. /usr/bin/env can do it as well, but shebang allows just single 
argument. Latest GNU env versions are able to split passed string to 
separate argument (-S option), but currently interpreting of script 
arguments as emacs options are suppressed by -- before "$@", so they are 
passed as `argv' list elements.

#!/usr/bin/env -S emacs --quick --script

should work, but it is less portable since relies on recent GNU env 
version and less safe since script options may modify emacs behavior.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Major mode of orgweb/publish.sh?
  2023-04-19  9:49       ` Bastien Guerry
@ 2023-04-21  3:09         ` Ruijie Yu via General discussions about Org-mode.
  0 siblings, 0 replies; 11+ messages in thread
From: Ruijie Yu via General discussions about Org-mode. @ 2023-04-21  3:09 UTC (permalink / raw)
  To: Bastien Guerry
  Cc: Ihor Radchenko, Ruijie Yu via General discussions about Org-mode.


Bastien Guerry <bzg@gnu.org> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>>> Converted the `load' into `require' because it allows someone working on a local
>>> repo to `eval-buffer' successfully, given that the individual installs these
>>> dependencies from GNU/NonGNU Elpa.  Previously, due to the hard-coded path,
>>> `eval-buffer' would not be successful.
>>
>> Looks reasonable, but I will let Bastien decide on this. He is the
>> author of this file.
>
> LGTM too!  Please go ahead, thanks,

Thanks, I'll include this part in my translation patchset if you don't
mind.

-- 
Best,


RY

[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-04-21  3:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-14  7:49 Major mode of orgweb/publish.sh? Ruijie Yu via General discussions about Org-mode.
2023-04-14  8:11 ` Ruijie Yu via General discussions about Org-mode.
2023-04-14  8:15   ` Ruijie Yu via General discussions about Org-mode.
2023-04-14  8:28     ` Ihor Radchenko
2023-04-14  9:20       ` Ruijie Yu via General discussions about Org-mode.
2023-04-19 16:54         ` Max Nikulin
2023-04-19  9:49       ` Bastien Guerry
2023-04-21  3:09         ` Ruijie Yu via General discussions about Org-mode.
2023-04-14  8:20 ` Ihor Radchenko
2023-04-14  8:19   ` Ruijie Yu via General discussions about Org-mode.
2023-04-14  8:54     ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).