Re: Lazy load of org-protocol (Max Nikulin)

2022-02-05 Thread Tianshu Wang


I have a similar demand that I implemented through the following and it
is currently working well.

(defadvice server-execute (before enable-org-protocol activate)
  (unless (featurep 'org-protocol) (require 'org-protocol)))

emacs-orgmode-requ...@gnu.org writes:

> Send Emacs-orgmode mailing list submissions to
>   emacs-orgmode@gnu.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   https://lists.gnu.org/mailman/listinfo/emacs-orgmode
> or, via email, send a message with subject or body 'help' to
>   emacs-orgmode-requ...@gnu.org
>
> You can reach the person managing the list at
>   emacs-orgmode-ow...@gnu.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Emacs-orgmode digest..."
>
>
> Today's Topics:
>
>1. Re: [BUG] loading ol-gnus returns an error [9.5
>   (release_9.5-194-gdb302d @
>   /home/oub/emacs/site-lisp/packages/org/)] (Ihor Radchenko)
>2. [SOLVED] (was: [BUG] loading ol-gnus returns an error [9.5
>   (release_9.5-194-gdb302d @
>   /home/oub/emacs/site-lisp/packages/org/)]) (Uwe Brauer)
>3. Re: [BUG] org-bibtex-yank does not recognise bibtex entry
>   [9.6 (9.6-??-e7ea951 ] (Ihor Radchenko)
>4. Re: Problem with org-babel and geiser (Ihor Radchenko)
>5. Lazy load of org-protocol (Max Nikulin)
>6. Re: Shell SRC blocks under Windows (H. Dieter Wilhelm)
>
>
> --
>
> Message: 1
> Date: Sat, 05 Feb 2022 17:37:01 +0800
> From: Ihor Radchenko 
> To: Uwe Brauer 
> Cc: emacs-orgmode@gnu.org
> Subject: Re: [BUG] loading ol-gnus returns an error [9.5
>   (release_9.5-194-gdb302d @ /home/oub/emacs/site-lisp/packages/org/)]
> Message-ID: <87tudd64ea.fsf@localhost>
> Content-Type: text/plain
>
> Uwe Brauer  writes:
>
>> Running a more or less recent master commit of org-mode and GNU emacs
>> when loading the ol-gnus file I receive the following error
>>
>>
>> Debugger entered--Lisp error: (void-variable file)
>>   (load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el")
>>   eval((load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el") nil)
>>   elisp--eval-last-sexp(nil)
>>   eval-last-sexp(nil)
>>   funcall-interactively(eval-last-sexp nil)
>>   call-interactively(eval-last-sexp nil nil)
>>   command-execute(eval-last-sexp)
>
> When does the error occur? Judging from the backtrace, you tried to
> evaluate some kind of elisp expression manually with eval-last-sexp. The
> expression appears to be
> (load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el")
>
> Indeed, file is undefined. I am not sure what Org has to do with the
> error.
>
> Best,
> Ihor
>
>
>
> --
>
> Message: 2
> Date: Sat, 05 Feb 2022 11:30:08 +0100
> From: Uwe Brauer 
> To: emacs-orgmode@gnu.org
> Subject: [SOLVED] (was: [BUG] loading ol-gnus returns an error [9.5
>   (release_9.5-194-gdb302d @ /home/oub/emacs/site-lisp/packages/org/)])
> Message-ID: <87y22pk3m7.fsf...@mat.ucm.es>
> Content-Type: text/plain; charset="utf-8"
>
>>>> "IR" == Ihor Radchenko  writes:
>
>> Uwe Brauer  writes:
>>> Running a more or less recent master commit of org-mode and GNU emacs
>>> when loading the ol-gnus file I receive the following error
>>>
>>>
>>> Debugger entered--Lisp error: (void-variable file)
>>> (load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el")
>>> eval((load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el") nil)
>>> elisp--eval-last-sexp(nil)
>>> eval-last-sexp(nil)
>>> funcall-interactively(eval-last-sexp nil)
>>> call-interactively(eval-last-sexp nil nil)
>>> command-execute(eval-last-sexp)
>
>> When does the error occur? Judging from the backtrace, you tried to
>> evaluate some kind of elisp expression manually with eval-last-sexp. The
>> expression appears to be
>> (load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el")
>
> Shame on me: it should be load-file
>
> I am very sorry. Forget it
> -- next part --
> A non-text attachment was scrubbed...
> Name: smime.p7s
> Type: application/pkcs7-signature
> Size: 5673 bytes
> Desc: not available
> URL: 
> <https://lists.gnu.org/archive/html/emacs-orgmode/attachments/20220205/d40c7d0c/attachment.bin>
>
> --
>
> Message: 3
> Date: Sat, 05 Feb 2022 19:22:59 +0800
> From: Ihor Radchenk

Re: Suggestion: convert dispatchers to use transient

2022-02-05 Thread João Pedro de Amorim Paula
On 05 February 2022 18:49, Samuel Wales  wrote:

> jus want to state the obvious here in case it is useful [but everybody
> probbly lready knows] --- not everybody uses packages or maybe trusts
> them has internet etc.

Indeed! What I posted assumes using packages, but they also work with
any package-desc object. So, if you download it locally and build the
package-desc for it it should also work, just have to put it in place of
the assq:

>> (let ((pkg-desc (assq 'org package-archive-contents)))
   
>>   (package-install pkg-desc))

Although Tim was referring to packages on ELPA that are also built-in.

-- 
João Pedro de A. Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


[PATCH] org-list-send-item: allow dest to be a buffer position

2022-02-05 Thread Sacha Chua
Passing an integer representing a buffer position to org-list-send-item
was failing because of the string-match-p, so here's something that lets
integers skip that part. I have copyright assignment papers on file.

Sacha


lisp/org-list.el: org-list-send-item: allow dest to be a buffer position

* lisp/org-list.el (org-list-send-item): Check if dest is a string
before matching it, to allow dest to be a buffer position.
---
 lisp/org-list.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org-list.el b/lisp/org-list.el
index 3533c8319..f1ab2ca76 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -1442,7 +1442,7 @@ (defun org-list-send-item (item dest struct)
  (save-excursion
(goto-char (org-list-get-last-item item struct prevs))
(point-at-eol)))
-((string-match-p "\\`[0-9]+\\'" dest)
+((and (stringp dest) (string-match-p "\\`[0-9]+\\'" dest))
  (let* ((all (org-list-get-all-items item struct prevs))
 (len (length all))
 (index (mod (string-to-number dest) len)))
-- 
2.25.1





Re: Suggestion: convert dispatchers to use transient

2022-02-05 Thread Samuel Wales
jus want to state the obvious here in case it is useful [but everybody
probbly lready knows] --- not everybody uses packages or maybe trusts
them has internet etc.

On 2/5/22, João Pedro de Amorim Paula  wrote:
> On 04 February 2022 08:30, Tim Cross  wrote:
>
>> I'm assuming it is, but I have to admit I'm still not 100% clear on
>> how Emacs handles the situation where you use a library that is both
>> built-in and available in ELPA. Does Emacs use the latest version
>> available or does it use the built-in version until you explicitly
>> select the ELPA versions?
>
> Welp, I happened to ponder the same question after trying to implement a
> function to install packages that are not installed already (I'm not
> using any helper configuration such as use-package, which would already
> handle this). From what I gathered empirically, it appears that if
> something is built-in, Emacs' package.el won't try to install -- it
> checks with package-installed-p on any call to package-install, which
> checks if the package is built-in with package-built-in-p as a fallback
> on cond --, but you can force installation from the archives by passing
> a package description object (defined as package-desc on package.el)
> instead of a symbol
>
> (let ((pkg-desc (assq 'org package-archive-contents)))
>   (package-install pkg-desc))
>
> and Emacs seems to be loading the newest version when it is a dependency
> of something else. Though I'm not really sure, as most of the packages I
> have from ELPA have the same version as the ones built-in on Emacs
> 28.0.91. I'll try and install Emacs 27 to check this out.
>
> In the mean time, I guess this would be a good opportunity to share a
> couple of functions I have with the purpose of installing packages.
>
> (defun pkg-description (package)
>   "Return the description for PACKAGE.
> If PACKAGE is installed, the will be present on `package-alist',
> otherwise look for it in `package-archive-contents'."
>   (or (cadr (assoc package package-alist))
>   (cadr (assoc package package-archive-contents
>
> (defun pkg-ensure-archive (package)
>   "Install PACKAGE from the archives, if not already installed."
>   (when-let ((pkg-desc (pkg-description package)))
> (unless (package-installed-p pkg-desc)
>   (package-install-from-archive pkg-desc
>
> (defun require-package (package  force)
>   "Ensure that PACKAGE is installed.
> If FORCE is non-nil, force installation regardless if PACKAGE is
> built-in or not.
>
> First, use `package-installed-p' to check if PACKAGE was
> installed via the Emacs package manager, otherwise, try to
> `require' PACKAGE; this ensures that we don't require PACKAGE if
> it was installed using the package manager. If both of those
> fail, run `package-refresh-contents' and install PACKAGE."
>   (unless (and (not force)
>(or (package-installed-p package)
>(require package nil 'no-error)))
> (unless (assoc package package-archive-contents)
>   (package-refresh-contents))
> (if force
> (pkg-ensure-archive package)
>   (package-install package
>
> On the last one, the main function that I use, if FORCE is non-nil it
> will download and install the package from the archives even if it is
> built-in.
>
> Best regards,
>
> --
> João Pedro de Amorim Paula
> IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com



Re: Shell SRC blocks under Windows

2022-02-05 Thread Matt


  On Sat, 05 Feb 2022 10:48:02 -0500 H. Dieter Wilhelm 
 wrote 

 > >> Is is it possible to extend org-mode's src blocks with
 > >> org-babel-shell-names to use either MSYS2 or MinGW shells (instead of
 > >> cmd.exe)?  Unfortunately ob-shell.el doesn't guide me further and I
 > >> can't find examples or the respective lisp files on how to define the
 > >> execution functions.
> 
 > Yes, you are right, when using 
 > 
 > > #+begin_src sh
 > 
 > It seems that I'm also running some bash shell! :
 
Yes, it's likely possible to run those shells. Whether or not it will be 
straight forward or not depends. It's not clear to me what you're trying to do.

First off,  you're looking in the right place. Unfortunately, ob-shell.el can 
be a little tricky to read.  All the shells are initialized through the 
=org-babel-shell-initialize= function. This creates a 
"org-babel-execute:" for each of the shells given in the 
=org-babel-shell-names= variable (where  is given by #+begin_src ) 
. The default shells are: ("sh" "bash" "zsh" "fish" "csh" "ash" "dash" "ksh" 
"mksh" "posh").   All  execute calls make their way through the God function 
=org-babel-sh-evaluate= (note: the "sh" in the function name appears to be 
cruft from when the ob-shell.el module was called "ob-sh.el"; it is not tied 
specifically to the sh shell).  Technically, which shell is used to evaluate 
the block depends on the source block parameters used. There are several 
possible paths.  Unless something weird is being done, however, the block 
should be evaluated by .  It looks like you're using a simple one-off 
shell, not a session or a shebang, so I'll speak to that.

For #+begin_src sh, the block will we evaluated by whatever  "sh" corresponds 
to in the environment Emacs is running in.  Under the hood, a call is made to 
the =shell= command and the =shell-file-name= variable gets set to whatever 
 the block specifies. The an binding happens in 
=org-babel-shell-initialize=.  So, open a command line environment that would 
be used to start Emacs and see what "sh" corresponds to:

which sh

That's the shell used by  #+begin_src sh.  Similarly, whatever "which bash" 
shows is what  #+begin_src bash uses.

This is why it would be surprising that cmd.exe would be used.  

I know that was a lot.  Depending, it may be as simple as updating the 
=org-babel-shell-names= and rerunning =org-babel-shell-initialize=.  Check the 
doc strings on those.  Otherwise, I hope this helps ob-shell.el guide you 
better.

 > But I'm not sure if I'm halfway there with "sh"?  I need to run the
 > following MSYS2 command AND switch between two arguments (for building
 > Emacs).
 > 
 >   \MSYS2\msys2_shell.cmd -mingw64
 > 
 > and
 > 
 >   \MSYS2\msys2_shell.cmd -msys.
 > 
 > How could I achieve this within a src block?

I'm not sure I follow you here.   Can you please describe what you're trying to 
do and the system you're using (e.g. Windows, GNU/Linux, Haiku) as well the 
shell used to run the Emacs instance you're doing this in?



Re: Problem with org-babel and geiser

2022-02-05 Thread Bob Heffernan
On 22-02-05 19:39, Ihor Radchenko wrote:
> It's not a good idea to modify Org packaged together with Emacs. For
> testing, you can just use the attached version of ob-scheme.el. Load
> your Emacs and Org mode, open the attached ob-scheme.el, and run M-x
> eval-buffer. That should be sufficient to test the proposed patch on
> your side.
>
> If the patch solves the problem you are experiencing, let us know. I
> will then apply the proposed patch upstream.
>
> Note that even if I apply the patch, it will only be available on the
> latest version of Org mode (Org 9.5.2). It is _not_ what is shipped
> together with your Emacs. You will need to upgrade your Org mode using
> M-x package-install. See
> https://orgmode.org/manual/Installation.html#Installation for details.

Ihor,

I did as you described and the patched version of ob-scheme.el *does* seem to 
solve the problem.

Thanks & best regards,
Bob



Re: Suggestion: convert dispatchers to use transient

2022-02-05 Thread João Pedro de Amorim Paula
On 04 February 2022 08:30, Tim Cross  wrote:

> I'm assuming it is, but I have to admit I'm still not 100% clear on
> how Emacs handles the situation where you use a library that is both
> built-in and available in ELPA. Does Emacs use the latest version
> available or does it use the built-in version until you explicitly
> select the ELPA versions?

Welp, I happened to ponder the same question after trying to implement a
function to install packages that are not installed already (I'm not
using any helper configuration such as use-package, which would already
handle this). From what I gathered empirically, it appears that if
something is built-in, Emacs' package.el won't try to install -- it
checks with package-installed-p on any call to package-install, which
checks if the package is built-in with package-built-in-p as a fallback
on cond --, but you can force installation from the archives by passing
a package description object (defined as package-desc on package.el)
instead of a symbol

(let ((pkg-desc (assq 'org package-archive-contents)))
  (package-install pkg-desc))

and Emacs seems to be loading the newest version when it is a dependency
of something else. Though I'm not really sure, as most of the packages I
have from ELPA have the same version as the ones built-in on Emacs
28.0.91. I'll try and install Emacs 27 to check this out.

In the mean time, I guess this would be a good opportunity to share a
couple of functions I have with the purpose of installing packages.

(defun pkg-description (package)
  "Return the description for PACKAGE.
If PACKAGE is installed, the will be present on `package-alist',
otherwise look for it in `package-archive-contents'."
  (or (cadr (assoc package package-alist))
  (cadr (assoc package package-archive-contents

(defun pkg-ensure-archive (package)
  "Install PACKAGE from the archives, if not already installed."
  (when-let ((pkg-desc (pkg-description package)))
(unless (package-installed-p pkg-desc)
  (package-install-from-archive pkg-desc

(defun require-package (package  force)
  "Ensure that PACKAGE is installed.
If FORCE is non-nil, force installation regardless if PACKAGE is
built-in or not.

First, use `package-installed-p' to check if PACKAGE was
installed via the Emacs package manager, otherwise, try to
`require' PACKAGE; this ensures that we don't require PACKAGE if
it was installed using the package manager. If both of those
fail, run `package-refresh-contents' and install PACKAGE."
  (unless (and (not force)
   (or (package-installed-p package)
   (require package nil 'no-error)))
(unless (assoc package package-archive-contents)
  (package-refresh-contents))
(if force
(pkg-ensure-archive package)
  (package-install package

On the last one, the main function that I use, if FORCE is non-nil it
will download and install the package from the archives even if it is
built-in.

Best regards,

-- 
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)


[9.5.2] [org-keys] [cursor keys with modifiers] ESC missing?

2022-02-05 Thread R Primus

Sat  5 Feb 2022 16:03:31 GMT

Hi,

Ref: 
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/org-keys.el#n463

For `(org-defkey org-mode-map (kbd "ESC ") #'org-metaleft)`, just 
wondering if:

1. this was intentionally left out, and
2. if so, what is the reason?

This causes user `surprise` when switching from using emacs/org-mode in
the terminal to a GUI session.

--
-primus (Train yourself and be your own master.)
Find something to love in whatever you are doing - it's all about mindset.
"First, solve the problem.  Then, write the code." - John Johnson
"Narrowness of experience leads to narrowness of imagination." - Rob Pike
https://www.catb.org/esr/faqs/smart-questions.html
https://www.chiark.greenend.org.uk/~sgtatham/bugs.html



Re: Lazy load of org-protocol

2022-02-05 Thread Jim Porter

On 2/5/2022 3:54 AM, Max Nikulin wrote:

I would prefer to avoid
    (require 'org-protocol)
in emacs init file and to postpone loading till invocation of 
emacsclient with org-protocol URI.


The problem is a hack in org-protocol. URIs are actually treated as 
(relative) file names and magic is achieved in an advice for 
`server-visit-files' function. So the advice must be installed in advance.


My first idea was to avoid such magic and to create autoload function 
org-protocol-from-argv with body similar to that advice. If it were 
possible to get arguments from `command-line-args-left' then invocation 
would look like


    emacsclient --eval '(org-protocol-from-argv)' 
'org-protocol:/store-link?url=u1=t1'


Unfortunately it is against design of emacs server protocol. If --eval 
option is given than everything other is considered as independent 
expressions. At the lower level there is no way to transfer `argv` as a 
list from client to server process.


I've thought a bit about how to improve this too. One further issue with 
the current implementation is that when emacsclient invokes the 
alternate editor (usually to start the "main" emacs instance), 
org-protocol: links no longer work correctly. That's because only the 
emacsclient itself (through `server-visit-files') knows what to do with 
them.


I think the problem really starts in emacsclient's command line 
handling. You can see this in other situations too. For example, Emacs 
can be configured as your system's mailto: URL handler. (The file 
etc/emacsclient-mail.desktop in the Emacs repo does this.) The command 
to use for a new Emacs instance is simple:


  emacs -f message-mailto %u

However, doing this for emacsclient is harder:

  emacsclient --alternate-editor= --create-frame --eval 
"(message-mailto \\"%u\\")"


There's no problem with "--alternate-editor=" and "--create-frame", but 
the fact that emacsclient requires evaling the function call that way 
is: if %u holds a string with quotation marks, this will break, and 
worse, could even result in arbitrary code being executed. (In practice, 
this is probably rare, since URLs are generally URL-encoded, and so 
don't have literal quotes in them.)


As a result, I think a good first step might be to add support for 
"--funcall" to emacsclient, just like the regular emacs binary. (The 
"-f" shorthand won't work though, since emacsclient already uses that 
for "--server-file"). This would simplify the `message-mailto' case 
above and would also allow org-protocol to do something similar:


  emacsclient --funcall org-protocol-capture %u

Then, so long as `org-protocol-capture' has an autoload, this would Just 
Work, and org-protocol.el would be lazily loaded. Hopefully, this could 
also be forwarded onto the alternate editor so that when the user open 
an org-protocol: URL when Emacs is closed, it still handles the URL 
correctly.


That said, in the short term, you could try out something like:

  emacsclient --eval "(org-protocol-capture \\"%u\\")"

Of course, that has the quoting issues I mentioned above, but it could 
be helpful for developing a proof of concept.


- Jim



Re: [BUG] org-bibtex-yank does not recognise bibtex entry [9.6 (9.6-??-e7ea951 ]

2022-02-05 Thread Günter Lichtenberg
Ihor Radchenko  writes:

> Günter Lichtenberg  writes:
>
>> In short:
>> Expected: Bibtex text is yanked as an orgmode entry
>> Actually Happening: Error thrown, nothing yanked
>
> Thanks for the report!
> Fixed on bugfix via 7543da99.

Great! Can confirm it works again.

Thanks a lot!
gl

–
Günter Lichtenberg
m...@guenterlichtenberg.de


[PATCH] org-agenda: Skip formatting if format string is ""

2022-02-05 Thread Samim Pezeshki
Hi!

I had contributed a patch which was merged at
commit 90a9ee17410a4b6663f5957c653258e9f9418d7d .

This commit prevents having extra spaces when the TODO format string is an
empty string ("").  It was not working properly, with this patch now it
works correctly.

Attached is the screenshot of the bug, you see there is an extra space in
the place of the TODO keyword. The third heading (Meditate) has a TODO
keyword, and the org-agenda-todo-keyword-format is set to an empty string.


Thanks,
Samim
From 7e49286c49ab342f91504205fc72ac6a8d095a1f Mon Sep 17 00:00:00 2001
From: Samim Pezeshki 
Date: Sat, 5 Feb 2022 20:11:19 +0330
Subject: [PATCH] lisp/org-agenda.el: Fix bug in `org-agenda-highlight-todo'

* lisp/org-agenda.el (org-agenda-highlight-todo): Skip formatting
the to-do keyword when `org-agenda-todo-keyword-format' is the
empty string.

TINYCHANGE
---
 lisp/org-agenda.el | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 9bc44a56e..fea0675e7 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -7634,13 +7634,13 @@ The optional argument TYPE tells the agenda type."
 	(setq x
 		  (concat
 		   (substring x 0 (match-end 1))
-   (unless (string= org-agenda-todo-keyword-format "")
-		 (format org-agenda-todo-keyword-format
-			 (match-string 2 x)))
-   ;; Remove `display' property as the icon could leak
-		   ;; on the white space.
-		   (org-add-props " " (org-plist-delete (text-properties-at 0 x)
-'display))
+   (unless (string= org-agenda-todo-keyword-format "")
+ (format org-agenda-todo-keyword-format
+ (match-string 2 x))
+ ;; Remove `display' property as the icon could leak
+ ;; on the white space.
+ (org-add-props " " (org-plist-delete (text-properties-at 0 x)
+  'display)))
(substring x (match-end 3)))
   x)))
 
-- 
2.35.1



Re: Shell SRC blocks under Windows

2022-02-05 Thread H. Dieter Wilhelm
Michael Powe  writes:

> On 2/4/2022 15:15, H. Dieter Wilhelm wrote:
>> Hello
>>
>> I installed the software distribution MSYS2 https://www.msys2.org/.  And
>> I'd like to call its various shells in org src blocks.  First I tried to
>> set explicit-shell-file-name but then my LaTeX exports don't work any
>> longer.
>>
>> Is is it possible to extend org-mode's src blocks with
>> org-babel-shell-names to use either MSYS2 or MinGW shells (instead of
>> cmd.exe)?  Unfortunately ob-shell.el doesn't guide me further and I
>> can't find examples or the respective lisp files on how to define the
>> execution functions.
>>
>> GNU Emacs 28.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30,
>> cairo version 1.15.10) of 2022-01-14
>>
>> Org mode version 9.4.6 (9.4.6-13-g4be129-elpaplus @
>> /home/dieter/.emacs.d/elpa/org-plus-contrib-20210920/)
>
> I'm not aware that I did anything special to get these results, except 
> add `(shell . t)` to `org-babel-load-languages`. I mean, it is entirely 
> possible that I did, in some other context. I think it's just a matter 
> of having bash in your path.

Yes, you are right, when using 

> #+begin_src sh

It seems that I'm also running some bash shell! :-) Previously I was
using the src block in this way:

  #+begin_src shell

and here the shell seems to be com.exe.

But I'm not sure if I'm halfway there with "sh"?  I need to run the
following MSYS2 command AND switch between two arguments (for building
Emacs).

  \MSYS2\msys2_shell.cmd -mingw64

and

  \MSYS2\msys2_shell.cmd -msys.

How could I achieve this within a src block?

Thanks 



Lazy load of org-protocol

2022-02-05 Thread Max Nikulin

Hi.

I would prefer to avoid
   (require 'org-protocol)
in emacs init file and to postpone loading till invocation of 
emacsclient with org-protocol URI.


The problem is a hack in org-protocol. URIs are actually treated as 
(relative) file names and magic is achieved in an advice for 
`server-visit-files' function. So the advice must be installed in advance.


My first idea was to avoid such magic and to create autoload function 
org-protocol-from-argv with body similar to that advice. If it were 
possible to get arguments from `command-line-args-left' then invocation 
would look like


   emacsclient --eval '(org-protocol-from-argv)' 
'org-protocol:/store-link?url=u1=t1'


Unfortunately it is against design of emacs server protocol. If --eval 
option is given than everything other is considered as independent 
expressions. At the lower level there is no way to transfer `argv` as a 
list from client to server process.


It seems, it works if I add another advice to init.el that loads 
org-protocol on demand:


(defadvice server-visit-files (before org-protocol-lazy-load activate)
  (and (not (featurep 'org-protocol))
   (memq nil
 (mapcar (lambda (loc)
   ;; loc: (file-name . (line . column))
		   (not (string-match-p "\\(?:^\\|[/]\\)org-protocol:" (car 
loc

 (ad-get-arg 0)))
   (progn
 (require 'org-protocol)
 ;; copy of org-protocol-detect-protocol-server advice,
 ;; move to a dedicated function
 (let ((flist (if org-protocol-reverse-list-of-files
  (reverse  (ad-get-arg 0))
(ad-get-arg 0)))
   (client (ad-get-arg 1)))
   (catch 'greedy
 (dolist (var flist)
   ;; `\' to `/' on windows.  FIXME: could this be done any better?
   (let ((fname  (expand-file-name (car var
 (setq fname (org-protocol-check-filename-for-protocol
  fname (member var flist)  client))
 (if (eq fname t) ;; greedy? We need the t return value.
 (progn
   (ad-set-arg 0 nil)
   (throw 'greedy t))
   (if (stringp fname) ;; probably filename
   (setcar var fname)
 (ad-set-arg 0 (delq var (ad-get-arg 0

I hope, copy of original advice may be avoided by moving its body to a 
separate function in org-protocol.


Do you have have better ideas how to avoid eager loading of org-protocol 
from init file?





Re: Problem with org-babel and geiser

2022-02-05 Thread Ihor Radchenko
Bob Heffernan  writes:

> Thank you for your response.
> The patch you linked does seem to be intended to fix this issue.
>
> However, I have no experience with applying a patch (to Emacs or anything 
> else).
> On my system, ob-scheme.el.gz can be found at
> /usr/share/emacs/27.2/lisp/org
> can I uncompress the file, patch that, then compress again?
>
> Or, would I need to download the Emacs source, apply the patch and then 
> recompile?

It's not a good idea to modify Org packaged together with Emacs. For
testing, you can just use the attached version of ob-scheme.el. Load
your Emacs and Org mode, open the attached ob-scheme.el, and run M-x
eval-buffer. That should be sufficient to test the proposed patch on
your side.

If the patch solves the problem you are experiencing, let us know. I
will then apply the proposed patch upstream.

Note that even if I apply the patch, it will only be available on the
latest version of Org mode (Org 9.5.2). It is _not_ what is shipped
together with your Emacs. You will need to upgrade your Org mode using
M-x package-install. See
https://orgmode.org/manual/Installation.html#Installation for details.

Best,
Ihor

;;; ob-scheme.el --- Babel Functions for Scheme  -*- lexical-binding: t; -*-

;; Copyright (C) 2010-2022 Free Software Foundation, Inc.

;; Authors: Eric Schulte
;;  Michael Gauland
;; Keywords: literate programming, reproducible research, scheme
;; Homepage: https://orgmode.org

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see .

;;; Commentary:

;; Now working with SBCL for both session and external evaluation.
;;
;; This certainly isn't optimally robust, but it seems to be working
;; for the basic use cases.

;;; Requirements:

;; - a working scheme implementation
;;   (e.g. guile https://www.gnu.org/software/guile/guile.html)
;;
;; - for session based evaluation geiser is required, which is available from
;;   ELPA.

;;; Code:
(require 'ob)
(require 'geiser nil t)
(require 'geiser-impl nil t)
(defvar geiser-repl--repl) ; Defined in geiser-repl.el
(defvar geiser-impl--implementation)   ; Defined in geiser-impl.el
(defvar geiser-scheme-implementation)  ; Defined in geiser-impl.el
(defvar geiser-default-implementation) ; Defined in geiser-impl.el
(defvar geiser-active-implementations) ; Defined in geiser-impl.el
(defvar geiser-debug-show-debug-p) ; Defined in geiser-debug.el
(defvar geiser-debug-jump-to-debug-p)  ; Defined in geiser-debug.el
(defvar geiser-repl-use-other-window)  ; Defined in geiser-repl.el
(defvar geiser-repl-window-allow-split) ; Defined in geiser-repl.el

(declare-function run-geiser "ext:geiser-repl" (impl))
(declare-function geiser-mode "ext:geiser-mode" ())
(declare-function geiser-eval-region "ext:geiser-mode"
  (start end  and-go raw nomsg))
(declare-function geiser-repl-exit "ext:geiser-repl" ( arg))
(declare-function geiser-eval--retort-output "ext:geiser-eval" (ret))
(declare-function geiser-eval--retort-result-str "ext:geiser-eval" (ret prefix))

(defcustom org-babel-scheme-null-to 'hline
  "Replace `null' and empty lists in scheme tables with this before returning."
  :group 'org-babel
  :version "26.1"
  :package-version '(Org . "9.1")
  :type 'symbol)

(defvar org-babel-default-header-args:scheme '()
  "Default header arguments for scheme code blocks.")

(defun org-babel-expand-body:scheme (body params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (org-babel--get-vars params))
(prepends (cdr (assq :prologue params)))
(postpends (cdr (assq :epilogue params
(concat (and prepends (concat prepends "\n"))
(if (null vars) body
  (format "(let (%s)\n%s\n)"
  (mapconcat
   (lambda (var)
 (format "%S" (print `(,(car var) ',(cdr var)
   vars
   "\n  ")
  body))
(and postpends (concat "\n" postpends)


(defvar org-babel-scheme-repl-map (make-hash-table :test #'equal)
  "Map of scheme sessions to session names.")

(defun org-babel-scheme-cleanse-repl-map ()
  "Remove dead buffers from the REPL map."
  (maphash
   (lambda (x y) (unless (buffer-name y) (remhash x org-babel-scheme-repl-map)))
   org-babel-scheme-repl-map))

(defun org-babel-scheme-get-session-buffer 

Re: [BUG] org-bibtex-yank does not recognise bibtex entry [9.6 (9.6-??-e7ea951 ]

2022-02-05 Thread Ihor Radchenko
Günter Lichtenberg  writes:

> In short:
> Expected: Bibtex text is yanked as an orgmode entry
> Actually Happening: Error thrown, nothing yanked

Thanks for the report!
Fixed on bugfix via 7543da99.

Best,
Ihor



[SOLVED] (was: [BUG] loading ol-gnus returns an error [9.5 (release_9.5-194-gdb302d @ /home/oub/emacs/site-lisp/packages/org/)])

2022-02-05 Thread Uwe Brauer
>>> "IR" == Ihor Radchenko  writes:

> Uwe Brauer  writes:
>> Running a more or less recent master commit of org-mode and GNU emacs
>> when loading the ol-gnus file I receive the following error
>> 
>> 
>> Debugger entered--Lisp error: (void-variable file)
>> (load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el")
>> eval((load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el") nil)
>> elisp--eval-last-sexp(nil)
>> eval-last-sexp(nil)
>> funcall-interactively(eval-last-sexp nil)
>> call-interactively(eval-last-sexp nil nil)
>> command-execute(eval-last-sexp)

> When does the error occur? Judging from the backtrace, you tried to
> evaluate some kind of elisp expression manually with eval-last-sexp. The
> expression appears to be
> (load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el")

Shame on me: it should be load-file

I am very sorry. Forget it


smime.p7s
Description: S/MIME cryptographic signature


Re: [BUG] loading ol-gnus returns an error [9.5 (release_9.5-194-gdb302d @ /home/oub/emacs/site-lisp/packages/org/)]

2022-02-05 Thread Ihor Radchenko
Uwe Brauer  writes:

> Running a more or less recent master commit of org-mode and GNU emacs
> when loading the ol-gnus file I receive the following error
>
>
> Debugger entered--Lisp error: (void-variable file)
>   (load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el")
>   eval((load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el") nil)
>   elisp--eval-last-sexp(nil)
>   eval-last-sexp(nil)
>   funcall-interactively(eval-last-sexp nil)
>   call-interactively(eval-last-sexp nil nil)
>   command-execute(eval-last-sexp)

When does the error occur? Judging from the backtrace, you tried to
evaluate some kind of elisp expression manually with eval-last-sexp. The
expression appears to be
(load file "/home/oub/emacs/site-lisp/packages/org/ol-gnus.el")

Indeed, file is undefined. I am not sure what Org has to do with the
error.

Best,
Ihor