Re: Major mode of orgweb/publish.sh?

2023-04-20 Thread General discussions about Org-mode.


Bastien Guerry  writes:

> Ihor Radchenko  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.]



Re: Major mode of orgweb/publish.sh?

2023-04-19 Thread Max Nikulin

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.





Re: Major mode of orgweb/publish.sh?

2023-04-19 Thread Bastien Guerry
Ihor Radchenko  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



Re: Major mode of orgweb/publish.sh?

2023-04-14 Thread General discussions about Org-mode.


Ihor Radchenko  writes:

> Ruijie Yu via "General discussions about Org-mode."
>  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



Re: Major mode of orgweb/publish.sh?

2023-04-14 Thread Ihor Radchenko
Ruijie Yu  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 .
Support Org development at ,
or support my work at 



Re: Major mode of orgweb/publish.sh?

2023-04-14 Thread General discussions about Org-mode.


Ihor Radchenko  writes:

> Ruijie Yu via "General discussions about Org-mode."
>  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



Re: Major mode of orgweb/publish.sh?

2023-04-14 Thread Ihor Radchenko
Ruijie Yu via "General discussions about Org-mode."
 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 .
Support Org development at ,
or support my work at 



Re: Major mode of orgweb/publish.sh?

2023-04-14 Thread Ihor Radchenko
Ruijie Yu via "General discussions about Org-mode."
 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 .
Support Org development at ,
or support my work at 



Re: Major mode of orgweb/publish.sh?

2023-04-14 Thread General discussions about Org-mode.

Ruijie Yu  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.

>From 90fd8ecc39cb279ee27e0db2f637f60c7b80af07 Mon Sep 17 00:00:00 2001
From: Ruijie Yu 
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


-- 
Best,


RY


Re: Major mode of orgweb/publish.sh?

2023-04-14 Thread General discussions about Org-mode.


Ruijie Yu via "General discussions about Org-mode."  
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