Re: [BUG] No newline at end of exported HTML file [9.6.6 (release_9.6.6 @ /Applications/MacPorts/Emacs.app/Contents/Resources/lisp/org/)]

2023-10-08 Thread YE
>
>> Exporting HTML file from Org-mode, f.i. with `org-html-export-to-html',
>> I expect to get a newline after the closing  tag, but it's not
>> added. I believe this used to work with previous versions of Org-mode.
>> Am I missing something?
>
> `org-html-template' never ever had a newline at the end of the generated
> html file.

Yes, I see that. It looks like there was something else that resulted in
a newline added at the end of the exported, including published, HTML
files (in previous Emacs versions).

> May you please explain why missing newline is a problem?

It's not necessarily a problem, since HTML parser implementations are
permissive. Still, a couple of arguments for adding it by default:

1. diff tools output "\ No newline at end of file" message when a
newline is missing. Supposedly, it's not optimal for default behavior.

2. POSIX.1-2017 states:
"3.206 Line
A sequence of zero or more non-  characters plus a terminating
 character."

3. Ending a line of text with a particular identifier is rather a
canonical approach.




Re: [the cryptic @@#$7]

2023-10-08 Thread Uwe Brauer

   > Uwe Brauer  writes:

   > The ref "remote(table1,@2$7..@>$7)" targets a range, containing all fields 
of
   > colum 7.  So, for each field, you get the same value: an array
   > containing all the field values: [22, 19, 19].



   > See (info "(org) References"), in the section:
   >"Field coordinates in formulas"

   > "‘@#’ is substituted with the row number of the field where the
   > current result will go to".

Aha, and has the benefit that the lookup call is not needed, but is more 
cryptic thanks for clarifying this.


-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of Ukraine.
I support the EU membership of Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/


smime.p7s
Description: S/MIME cryptographic signature


Re: equivalent of VLOOKUP (in ods) to org-table

2023-10-08 Thread Uwe Brauer

> Uwe Brauer  writes:


>#+TBLFM: $3='(org-lookup-first $1 '(remote(table1, @I$1..@II$1)) 
> '(remote(table1, @I$7..@II$7)))

Oops no I tried 

$3='(org-lookup-first '(remote(table1, @1$7..@4$7)))

And that gave error

So thanks a lot

>#+TBLFM: $5=vsum($2..$4)

> IIUC, it seems to be the result that you're expecting.

> Bruno





-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of Ukraine.
I support the EU membership of Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/


smime.p7s
Description: S/MIME cryptographic signature


Re: [the cryptic @@#$7] (was: equivalent of VLOOKUP (in ods) to org-table)

2023-10-08 Thread Bruno Barbier
Uwe Brauer  writes:

 "UB" == Uwe Brauer  writes:
>
 "BB" == Bruno Barbier  writes:
>>> Hi Uwe,
>
>>> Uwe Brauer  writes:
 so the question is what is equivalent of VLOOKUP in org.
>
>>> Did you check these lookup functions in the Org manual?
>
>>> (info "(org) Lookup functions")
>
>
> I ask differently why does the following solution not work
>
> #+Name: table1
> | Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh1 |
> |+-+-+-+-+-+|
> | Smith  |   2 |   3 |   4 |   6 |   7 | 22 |
> | Miller |   2 |  10 |   1 |   1 |   5 | 19 |
> | Wick   |   1 |   2 |   3 |  10 |   2 | 18 |
> #+TBLFM: $7=vsum($2..$6);f2
>
>
>
> #+Name: final
> | Name   | Some | ResSh1   |
> |+--+--|
> | Smith  |4 | [22, 19, 18] |
> | Miller |4 | [22, 19, 18] |
> | Wick   |4 | [22, 19, 18] |
> |+--+--|
> #+TBLFM: @2$3..@>$3=remote(table1,@2$7..@>$7)

The ref "remote(table1,@2$7..@>$7)" targets a range, containing all fields of
colum 7.  So, for each field, you get the same value: an array
containing all the field values: [22, 19, 19].


>
> But this solution does, what does @@#$7 mean?

See (info "(org) References"), in the section:
   "Field coordinates in formulas"

"‘@#’ is substituted with the row number of the field where the
current result will go to".


> #+Name: final2
> | Name   | Some | ResSh1 |
> |+--+|
> | Smith  |4 | 22 |
> | Miller |4 | 19 |
> | Wick   |4 | 18 |
> |+--+|
> #+TBLFM: @2$3..@>$3=remote(table1,@@#$7)

With this formula, your remote reference targets the field, that is in
the same row number as the computed field in final.

Here is the same table, with some extra columns that show the
intermediate steps:

   #+Name: final2
   | Name   | Some | ResSh1 | What is '@#'? | Which ref? |
   |+--++---+|
   | Smith  |4 | 22 | 2 | @2$7   |
   | Miller |4 | 19 | 3 | @3$7   |
   | Wick   |4 | 18 | 4 | @4$7   |
   |+--++---+|
   #+TBLFM: @2$3..@>$3=remote(table1,@@#$7)
   #+TBLFM: @2$4..@>$4=@#
   #+TBLFM: @2$5..@>$5='(concat "@" (format "%d" @#) "$" "7")

Bruno



>
>
>
> -- 
> Warning: Content may be disturbing to some audiences
> I strongly condemn Putin's war of aggression against Ukraine.
> I support to deliver weapons to Ukraine's military. 
> I support the NATO membership of Ukraine.
> I support the EU membership of Ukraine. 
> https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/



Re: equivalent of VLOOKUP (in ods) to org-table

2023-10-08 Thread Bruno Barbier
Uwe Brauer  writes:

 "BB" == Bruno Barbier  writes:
>> Did you check these lookup functions in the Org manual?
>>(info "(org) Lookup functions")
>
>
> Yes of course, but I am unable to obtain the same result as I do using
> the remote call.

Did you try something like this ?

   #+NAME: table1
   | Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh1 |
   |+-+-+-+-+-+|
   | Smith  |   2 |   3 |   4 |   6 |   7 | 22 |
   | Miller |   2 |  10 |   1 |   1 |   5 | 19 |
   | Wick   |   1 |   2 |   3 |  10 |   2 | 18 |
   #+TBLFM: $7=vsum($2..$6);f2


   #+NAME: table2   
   | Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh2 |
   |+-+-+-+-+-+|
   | Smith  |   8 |   3 |   5 |   8 |   9 | 33 |
   | Miller |   2 |   1 |   6 |   9 |   3 | 21 |
   | Wick   |   1 |   5 |   9 |   1 |   2 | 18 |
   #+TBLFM: $7=vsum($2..$6);f2

   | Name   |   | ResSh1 | ResSh2 | Total |
   |+---+++---|
   | Smith  | 4 | 22 | 33 |59 |
   | Miller | 4 | 19 | 21 |44 |
   | Wick   | 4 | 18 | 18 |40 |
   #+TBLFM: $3='(org-lookup-first $1 '(remote(table1, @I$1..@II$1)) 
'(remote(table1, @I$7..@II$7)))
   #+TBLFM: $5=vsum($2..$4)

IIUC, it seems to be the result that you're expecting.

Bruno


>
> Uwe 
> -- 
> Warning: Content may be disturbing to some audiences
> I strongly condemn Putin's war of aggression against Ukraine.
> I support to deliver weapons to Ukraine's military. 
> I support the NATO membership of Ukraine.
> I support the EU membership of Ukraine. 
> https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/



[the cryptic @@#$7] (was: equivalent of VLOOKUP (in ods) to org-table)

2023-10-08 Thread Uwe Brauer
>>> "UB" == Uwe Brauer  writes:

>>> "BB" == Bruno Barbier  writes:
>> Hi Uwe,

>> Uwe Brauer  writes:
>>> so the question is what is equivalent of VLOOKUP in org.

>> Did you check these lookup functions in the Org manual?

>> (info "(org) Lookup functions")


I ask differently why does the following solution not work

#+Name: table1
| Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh1 |
|+-+-+-+-+-+|
| Smith  |   2 |   3 |   4 |   6 |   7 | 22 |
| Miller |   2 |  10 |   1 |   1 |   5 | 19 |
| Wick   |   1 |   2 |   3 |  10 |   2 | 18 |
#+TBLFM: $7=vsum($2..$6);f2



#+Name: final
| Name   | Some | ResSh1   |
|+--+--|
| Smith  |4 | [22, 19, 18] |
| Miller |4 | [22, 19, 18] |
| Wick   |4 | [22, 19, 18] |
|+--+--|
#+TBLFM: @2$3..@>$3=remote(table1,@2$7..@>$7)

But this solution does, what does @@#$7 mean?

#+Name: final2
| Name   | Some | ResSh1 |
|+--+|
| Smith  |4 | 22 |
| Miller |4 | 19 |
| Wick   |4 | 18 |
|+--+|
#+TBLFM: @2$3..@>$3=remote(table1,@@#$7)




-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of Ukraine.
I support the EU membership of Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/


smime.p7s
Description: S/MIME cryptographic signature


Re: equivalent of VLOOKUP (in ods) to org-table

2023-10-08 Thread Uwe Brauer
>>> "BB" == Bruno Barbier  writes:

> Hi Uwe,

> Uwe Brauer  writes:
>> so the question is what is equivalent of VLOOKUP in org.

> Did you check these lookup functions in the Org manual?

>(info "(org) Lookup functions")


Yes of course, but I am unable to obtain the same result as I do using
the remote call.

Uwe 
-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of Ukraine.
I support the EU membership of Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/


smime.p7s
Description: S/MIME cryptographic signature


Re: equivalent of VLOOKUP (in ods) to org-table

2023-10-08 Thread Bruno Barbier


Hi Uwe,

Uwe Brauer  writes:
> so the question is what is equivalent of VLOOKUP in org.

Did you check these lookup functions in the Org manual?

   (info "(org) Lookup functions")


Bruno.



>
> I came up with the remote command that results in a similar result, (I did 
> not want to use third party packages like 
> orgtbl-aggregate. 
>
> #+begin_src 
> #+Name: table1
> | Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh1 |
> |+-+-+-+-+-+|
> | Smith  |   2 |   3 |   4 |   6 |   7 | 22 |
> | Miller |   2 |  10 |   1 |   1 |   5 | 19 |
> | Wick   |   1 |   2 |   3 |  10 |   2 | 18 |
> #+TBLFM: $7=vsum($2..$6);f2
>
>
> #+Name: table2   
> | Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh2 |
> |+-+-+-+-+-+|
> | Smith  |   8 |   3 |   5 |   8 |   9 | 33 |
> | Miller |   9 |   4 |   6 |   9 |   3 | 31 |
> | Wick   |   1 |   5 |   9 |   1 |   2 | 18 |
> |+-+-+-+-+-+|
> #+TBLFM: $7=vsum($2..$6);f2
>
> #+Name: final
> | Name   | Some | ResSh1 | ResSh2 | Final |
> |+--+++---|
> | Smith  |4 | 22 | 33 |59 |
> | Miller |4 | 19 | 31 |54 |
> | Wick   |4 | 18 | 18 |40 |
> |+--+++---|
> #+TBLFM: $3=remote(table1,@@#$7)::$4=remote(table2,@@#$7)::$5=vsum($2..$4);f2
> #+end_src
>
>
> The syntax with @@#$7 look cryptic to me, but I found it somewhere and it 
> works
> if somebody can suggest a simpler command that is closer to VLOOKUP I would 
> be grateful
>
> Thanks and regards
>
> Uwe Brauer 
>
> -- 
> Warning: Content may be disturbing to some audiences
> I strongly condemn Putin's war of aggression against Ukraine.
> I support to deliver weapons to Ukraine's military. 
> I support the NATO membership of Ukraine.
> I support the EU membership of Ukraine. 
> https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/



Re: A locale for Org?

2023-10-08 Thread Juergen Fenn



Am 08.10.23 um 17:16 Uhr schrieb Ihor Radchenko:
>> Is there a locale for Org?
> See "23.2 Language Environments" section of Emacs manual and
> `org-export-default-language'.

Ah, thanks, Ihor! It's anguage support vs. language environment in
Emacs! I forgot about the latter term. For all the rest, Org depends on
the general settings for Emacs. So I no longer have to set #+LANGUAGE in
every document.

Best regards,
Jürgen.



Re: A locale for Org?

2023-10-08 Thread Ihor Radchenko
Juergen Fenn  writes:

> I wonder whether there is a variable you can configure globally in your
> .emacs to make German the language of all documents Org will create,
> export, etc.?
>
> My locale on macOS is de_DE.UTF-8.
>
> Is there a locale for Org?

See "23.2 Language Environments" section of Emacs manual and
`org-export-default-language'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



A locale for Org?

2023-10-08 Thread Juergen Fenn
Hello,

I wonder whether there is a variable you can configure globally in your
.emacs to make German the language of all documents Org will create,
export, etc.?

My locale on macOS is de_DE.UTF-8.

Is there a locale for Org?

I have looked for language support in Org, but I only find support for
programming languages.

Thanks and best regards,
Jürgen.



Re: [PATCH] Fix org-[beginning|end]-of-line with arguments

2023-10-08 Thread Tomohisa Kuranari
Hi, Ihor

Thank you for your feedback.
I found your guidance on writing a clearer message, quoting Elisp symbols,
and the insights about indentation rules to be particularly valuable.

Not using line-number-at-pos is truly a great suggestion.
I've reworked the patch and also revised the commit message.
I kindly request another review. If there are any issues, I will make
further revisions.

Finally, the copyright assignment process was completed on 2023/09/20.
Thank you for letting me know.

On Thu, Oct 5, 2023 at 7:03 PM Ihor Radchenko  wrote:
>
> 倉成智久  writes:
>
> > In the current implementation, org-special-ctrl-a/e may not operate as 
> > expected.
> > For example, executing (org-beginning-of-line 2) relocates the cursor
> > to the start of the line, rather than after the heading symbols even
> > if org-special-ctrl-a/e is t.
> > (Movements to prior lines, such as (org-beginning-of-line 0), function
> > correctly.)
>
> > This is my first patch submission. If there are any shortcomings or
> > additional requirements needed, please do not hesitate to inform me. I
> > am open to feedback and willing to make any necessary adjustments.
>
> Thanks for the patch, and especially for providing tests!
> See my comments below.
>
> > Subject: [PATCH] lisp/org.el: Fix the issue with argumented function calls
>
> The above message is not very clear. It would be better if you summarize
> the commit purpose more precisely. For example,
> "org-beginning/end-of-line: Fix when moving to different line"
>
> > * lisp/org.el (org-beginning-of-line, org-end-of-line): Fix issue with 
> > org-special-ctrl-a/e not working correctly when moving with arguments
>
> Please, quote Elisp symbols like `org-special-ctrl-a/e'. Also, we
> usually limit the line width to default `fill-column'.
>
> > -   (when (or (> origin refpos) (= origin bol))
> > +   (when (or (> origin refpos)
> > + (= origin bol)
> > + (/= (line-number-at-pos origin) (line-number-at-pos bol)))
>
> This will work, but I am not a big fan of using `line-number-at-pos' -
> it is rather slow. May simply check (< origin bol)
>
> > -   (when (or (> origin after-bullet) (= (point) origin))
> > +   (when (or (> origin after-bullet)
> > + (= (point) origin)
> > + (/= (line-number-at-pos origin) (line-number-at-pos 
> > (point
>
> Same here - (< origin (point))
>
> > -(if (or (< origin tags) (= origin (line-end-position)))
> > +(if (or (< origin tags)
> > +(= origin (line-end-position))
> > +(/= (line-number-at-pos origin) (line-number-at-pos 
> > (point
>
> (> origin (line-end-position))
>
> Finally, your patch is on the edge of legally allowed contribution we are
> allowed to accept without copyright assignment. You may consider signing
> the copyright form as described in
> https://orgmode.org/worg/org-contribute.html#copyright. Or you can add
> "TINYCHANGE" to the commit message (see
> https://orgmode.org/worg/org-contribute.html#first-patch)
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at .
> Support Org development at ,
> or support my work at 



-- 
Tomohisa Kuranari
Email: tomohisa.kuran...@gmail.com


0001-org-beginning-end-of-line-Fix-when-moving-to-differe.patch
Description: Binary data


equivalent of VLOOKUP (in ods) to org-table

2023-10-08 Thread Uwe Brauer
Hi

I have regularly to deal with large tables, that I split in smaller ones and 
then try to connect them.

I have to export the resulting big table to ods, and in the ods case, I have 
several sheets and use the 
VLOOKUP command, like this

#+begin_src 
#+Name: table1
| Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh1 |
|+-+-+-+-+-+|
| Smith  |   2 |   3 |   4 |   6 |   7 | 22 |
| Miller |   2 |  10 |   1 |   1 |   5 | 19 |
| Wick   |   1 |   2 |   3 |  10 |   2 | 18 |
#+TBLFM: $7=vsum($2..$6);f2


#+Name: table2   
| Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh2 |
|+-+-+-+-+-+|
| Smith  |   8 |   3 |   5 |   8 |   9 | 33 |
| Miller |   2 |   1 |   6 |   9 |   3 | 21 |
| Wick   |   1 |   5 |   9 |   1 |   2 | 18 |
#+TBLFM: $7=vsum($2..$6);f2

| Name   |   | ResSh1  | ResSh2 
 | Total   |
|+---+-+-+-|
| Smith  | 3 | /=VLOOKUP(final.A2,table1.$A$1:$G$3,7,FALSE())/ | 
/=VLOOKUP(final.A2,table2.$A$1:$G$3,7,FALSE())/ | =SUM(C2:D2) |
| Miller | 3 | /=VLOOKUP(final.A3,table1.$A$1:$G$3,7,FALSE())/ | 
/=VLOOKUP(final.A3,table2.$A$1:$G$3,5,FALSE())/ | =SUM(C3:D3) |
| Wick   | 4 | /=VLOOKUP(final.A4,table1.$A$1:$G$4,7,FALSE())/ | 
/=VLOOKUP(final.A4,table2.$A$1:$G$4,7,FALSE())/ | =SUM(C4:D4) |
#+TBLFM: $5=SUM(@4$3:@4$4)
#+end_src


Maybe there are other solution in ods I don't  know, so the question is what is 
equivalent of VLOOKUP in org.

I came up with the remote command that results in a similar result, (I did not 
want to use third party packages like 
orgtbl-aggregate. 

#+begin_src 
#+Name: table1
| Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh1 |
|+-+-+-+-+-+|
| Smith  |   2 |   3 |   4 |   6 |   7 | 22 |
| Miller |   2 |  10 |   1 |   1 |   5 | 19 |
| Wick   |   1 |   2 |   3 |  10 |   2 | 18 |
#+TBLFM: $7=vsum($2..$6);f2


#+Name: table2   
| Name   | Ex1 | Ex2 | Ex2 | Ex4 | Ex5 | ResSh2 |
|+-+-+-+-+-+|
| Smith  |   8 |   3 |   5 |   8 |   9 | 33 |
| Miller |   9 |   4 |   6 |   9 |   3 | 31 |
| Wick   |   1 |   5 |   9 |   1 |   2 | 18 |
|+-+-+-+-+-+|
#+TBLFM: $7=vsum($2..$6);f2

#+Name: final
| Name   | Some | ResSh1 | ResSh2 | Final |
|+--+++---|
| Smith  |4 | 22 | 33 |59 |
| Miller |4 | 19 | 31 |54 |
| Wick   |4 | 18 | 18 |40 |
|+--+++---|
#+TBLFM: $3=remote(table1,@@#$7)::$4=remote(table2,@@#$7)::$5=vsum($2..$4);f2
#+end_src


The syntax with @@#$7 look cryptic to me, but I found it somewhere and it works
if somebody can suggest a simpler command that is closer to VLOOKUP I would be 
grateful

Thanks and regards

Uwe Brauer 

-- 
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the NATO membership of Ukraine.
I support the EU membership of Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/


smime.p7s
Description: S/MIME cryptographic signature


Re: [FR] A more general case than footnotes

2023-10-08 Thread Maske

Hi, Ihor

I overlooked the aspect of exporting.

I propose links to arbitrary points in different files.

Furthermore, I think it would be a very nice new feature, probably more 
opinions than mine should be heard.


Thanks

On 08/10/2023 11:18, Ihor Radchenko wrote:

Maske  writes:


*[n:102@978-84-362-7195-9]* The hash character is important in orgmode.

May you explain the purpose of @978-84-... part?
You seem to assume that a footnote always has a single reference,
which may or may not be the case in practice.

If there would be more than one reference, a behavior like that of footnotes 
would be appropriate?

If this was a question to me, I do not fully understand it.


The purpose of the @978-84-... part:
@978-84-362-7195-9 would work like the ID for internal links: 
[[id:978-84-362-7195-9]]. That would allow jumping to the correct heading from 
any file.
I am not a programmer, so the syntax I am sure could be more solid.  Example:


** Reference in file A
:PROPERTIES:
:ID:   978-84-362-7195-9
:END:
...
A “comment line” starts with a hash character (#) [n:102@978-84-362-7195-9] and 
either a whitespace character or the immediate end of the line.
...


** Notes in file B
[[id:978-84-362-7195-9]]: Link to heading in file A

[n:102@978-84-362-7195-9]: Link to an exact point in file A. Where the point is 
defined by the LABEL 102, and the file can be find thanks to the ID 
978-84-362-7195-9

I am a bit confused.
Do you propose footnotes to have definition in different file? Or do you
want a link to arbitrary point in different file?

For footnotes, we will need to arrange export to search the definition
and include it into the exported file, while links have different set of
requirements.



I propose

Re: [BUG] [PATCH] Add yank-media and DND handler [9.6.7 (9.6.7-g6eb773 @ /home/viz/lib/emacs/straight/build/org/)]

2023-10-08 Thread Visuwesh
[ஞாயிறு அக்டோபர் 08, 2023] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> This was far easier than I initially thought.  Patch attached.
>
> Thanks!
> I tried to install the patch and I have two more comments.
>
>> +(defun org-yank-image-autogen-filename ()
>> +  "Autogenerate filename for image in clipboard."
>> +  (format-time-string "clipboard-%Y-%m-%d-%H:%M"))
>
> This is too coarse - no more than a single unique image name per minute.
> What about the default value of `org-id-ts-format' - "%Y%m%dT%H%M%S.%6N"?
> This is guaranteed to be unique.

OK, now done.

>> +(defun org--image-yank-media-handler (mimetype data)
>> +  "Save image DATA of mime-type MIMETYPE and insert link at point.
>> +It is saved as per `org-yank-image-save-type'.  The name for the
>> +image is prompted and the extension is automatically added to the
>> +end."
>> ...
>> +(if (null (eq org-yank-image-save-type 'attach))
>> +(setq link (org-link-make-string
>> +(concat "file:" (file-relative-name absname))
>> +filename))
>
> I do not like that the inserted image link is with description. Images
> with description cannot be previewed by default. I think that no
> description would be more handy as one could then M-x yank-media
> followed by M-x org-display-inline-images to see the inserted image
> immediately.

I didn't know about this.  Now adjusted in the attached patch.

>From f2d13548b970ebde90ea0a04be7951ef92d220a9 Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Fri, 22 Sep 2023 20:11:41 +0530
Subject: [PATCH] Add support for yank-media and DND

* lisp/org.el (org-mode): Call the setup function for yank-media and
DND.
(org-setup-yank-dnd-handlers): Register yank-media-handler and DND
handler.
(org-yank-image-save-type, org-yank-image-file-name-function)
(org-dnd-default-attach-method, org-dnd-method): New defcustoms.
(org--image-yank-media-handler, org--copied-files-yank-media-handler)
(org--dnd-attach-file, org--dnd-local-file-handler, org--dnd-xds-method)
(org--dnd-xds-function): Add yank-media and DND handlers.

* etc/ORG-NEWS: Advertise the new features.
---
 etc/ORG-NEWS |  20 +
 lisp/org.el  | 224 ++-
 2 files changed, 243 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 252c5a9f9..c4a58dd4d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -596,6 +596,26 @@ return a matplotlib Figure object to plot. For output results, the
 current figure (as returned by =pyplot.gcf()=) is cleared before
 evaluation, and then plotted afterwards.
 
+*** Images and files in clipboard can be attached
+
+Org can now attach images in clipboard and files copied/cut to the
+clipboard from file managers using the ~yank-media~ command which also
+inserts a link to the attached file.  This command was added in Emacs 29.
+
+Images can be saved to a separate directory instead of being attached,
+customize ~org-yank-image-save-type~.
+
+Image filename chosen can be customized by setting
+~org-yank-image-file-name-function~ which by default autogenerates a
+filename based on the current time.
+
+*** Files and images can be attached by dropping onto Emacs
+
+Attachment method other than ~org-attach-method~ for dropped files can
+be specified using ~org-dnd-default-attach-method~.
+
+Images dropped also respect the value of ~org-yank-image-save-type~.
+
 ** New functions and changes in function arguments
 *** =TYPES= argument in ~org-element-lineage~ can now be a symbol
 
diff --git a/lisp/org.el b/lisp/org.el
index d0b2355ea..a7ec90f08 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4999,7 +4999,10 @@ The following commands are available:
   (org--set-faces-extend '(org-block-begin-line org-block-end-line)
  org-fontify-whole-block-delimiter-line)
   (org--set-faces-extend org-level-faces org-fontify-whole-heading-line)
-  (setq-local org-mode-loading nil))
+  (setq-local org-mode-loading nil)
+
+  ;; `yank-media' handler and DND support.
+  (org-setup-yank-dnd-handlers))
 
 ;; Update `customize-package-emacs-version-alist'
 (add-to-list 'customize-package-emacs-version-alist
@@ -20254,6 +20257,225 @@ it has a `diary' type."
 		(org-format-timestamp timestamp fmt t))
 	  (org-format-timestamp timestamp fmt (eq boundary 'end)))
 
+;;; Yank media handler and DND
+(defun org-setup-yank-dnd-handlers ()
+  "Setup the `yank-media' and DND handlers for buffer."
+  (setq-local dnd-protocol-alist
+  (cons '("^file:///" . org--dnd-local-file-handler)
+dnd-protocol-alist))
+  (when (fboundp 'yank-media-handler)
+(yank-media-handler "image/.*" #'org--image-yank-media-handler)
+;; Looks like different DEs go for different handler names,
+;; https://larsee.com/blog/2019/05/clipboard-files/.
+(yank-media-handler "x/special-\\(?:gnome\|KDE\|mate\\)-files"
+#'org--copied-files-yank-media-handler))
+  (when (boundp 

Re: Exporting elisp: and shell: links

2023-10-08 Thread Ihor Radchenko
Rudolf Adamkovič  writes:

>> Still, it would be nice to have _a_ variant compared to the current
>> state of affairs.
>
> Agreed.  If the link has no description, we can do a great job on
> exporting it.  Half of the victory, right there!
>
> Also, how about the following /simple/ idea for the description:
>
>   [[elisp:(server-start)][Launch Server]]
>   [[elisp:(server-start)][=M-x server-start RET=]]
>   
>   src_elisp[:exports code]{(server-start)} (Launch Server)
>   src_elisp[:exports code]{(server-start)} (=M-x server-start RET=)
>
> TL;DR We export the description, if any, in parentheses after the code.

See the attached diff, implementing your suggestion.
I am not sure if I like it.

Consider the following example file:


#+options: toc:nil author:nil

[[elisp:(message "Hello")]]

[[elisp:(message "Hello")][Message Hello]]


Without the diff, exporting to ASCII yields




[Message Hello]


[Message Hello] 


with the diff:


`(message "Hello")'

`(message "Hello")' (Message Hello)
---

For markdown:

without diff:
---
<(message "Hello")>

[Message Hello]((message "Hello"))

---

with:
---
`(message "Hello")`

`(message "Hello")` (Message Hello)
---

For html:

without diff:

with:
diff --git a/lisp/ol.el b/lisp/ol.el
index 20aab6bb8..d537709ac 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1377,7 +1377,29 @@ (defun org-link--open-elisp (path _)
 		 (call-interactively (read path
 (user-error "Abort")))
 
-(org-link-set-parameters "elisp" :follow #'org-link--open-elisp)
+(defun org-link--export-code (path description _ info  lang)
+  "Export executable link with PATH and DESCRIPTION.
+INFO is the current export info plist.
+LANG is the language name, as in #+begin_src lang.  For example, \"elisp\"
+or \"shell\"."
+  (concat
+   (org-export-data
+(org-element-create
+ 'inline-src-block
+ `( :language ,lang
+:value ,path
+:parameters ":exports code :noweb no :eval never"))
+info)
+   (when description (format " (%s)" description
+
+(defun org-link--export-elisp (path description _ info)
+  "Export elisp: link with PATH and DESCRIPTION according to INFO channel."
+  (org-link--export-code path description nil info "emacs-lisp"))
+
+(org-link-set-parameters
+ "elisp"
+ :follow #'org-link--open-elisp
+ :export #'org-link--export-elisp)
 
  "file" link type
 (org-link-set-parameters "file" :complete #'org-link-complete-file)
@@ -1435,7 +1457,14 @@ (defun org-link--open-shell (path _)
 		  clean-buffer-list-kill-buffer-names
 (user-error "Abort")))
 
-(org-link-set-parameters "shell" :follow #'org-link--open-shell)
+(defun org-link--export-shell (path description _ info)
+  "Export shell: link with PATH and DESCRIPTION according to INFO channel."
+  (org-link--export-code path description nil info "shell"))
+
+(org-link-set-parameters
+ "shell"
+ :follow #'org-link--open-shell
+ :export #'org-link--export-shell)
 
 
 ;;; Interactive Functions


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 


Re: [BUG] [PATCH] Add yank-media and DND handler [9.6.7 (9.6.7-g6eb773 @ /home/viz/lib/emacs/straight/build/org/)]

2023-10-08 Thread Ihor Radchenko
Visuwesh  writes:

> This was far easier than I initially thought.  Patch attached.

Thanks!
I tried to install the patch and I have two more comments.

> +(defun org-yank-image-autogen-filename ()
> +  "Autogenerate filename for image in clipboard."
> +  (format-time-string "clipboard-%Y-%m-%d-%H:%M"))

This is too coarse - no more than a single unique image name per minute.
What about the default value of `org-id-ts-format' - "%Y%m%dT%H%M%S.%6N"?
This is guaranteed to be unique.

> +(defun org--image-yank-media-handler (mimetype data)
> +  "Save image DATA of mime-type MIMETYPE and insert link at point.
> +It is saved as per `org-yank-image-save-type'.  The name for the
> +image is prompted and the extension is automatically added to the
> +end."
> ...
> +(if (null (eq org-yank-image-save-type 'attach))
> +(setq link (org-link-make-string
> +(concat "file:" (file-relative-name absname))
> +filename))

I do not like that the inserted image link is with description. Images
with description cannot be previewed by default. I think that no
description would be more handy as one could then M-x yank-media
followed by M-x org-display-inline-images to see the inserted image
immediately.

> + (org-link-make-string
> +  (concat (if separatep
> +  "file:"
> +"attachment:")
> +  (if separatep
> +  (expand-file-name (file-name-nondirectory filename)
> +org-yank-image-save-type)
> +(file-name-nondirectory filename)))

Same here.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [FR] A more general case than footnotes

2023-10-08 Thread Ihor Radchenko
Maske  writes:

>>>
>>> *[n:102@978-84-362-7195-9]* The hash character is important in orgmode.
>> May you explain the purpose of @978-84-... part?
>> You seem to assume that a footnote always has a single reference,
>> which may or may not be the case in practice.
>
> If there would be more than one reference, a behavior like that of footnotes 
> would be appropriate?

If this was a question to me, I do not fully understand it.

> The purpose of the @978-84-... part:
> @978-84-362-7195-9 would work like the ID for internal links: 
> [[id:978-84-362-7195-9]]. That would allow jumping to the correct heading 
> from any file.

> I am not a programmer, so the syntax I am sure could be more solid.  Example:
>
>
> ** Reference in file A
> :PROPERTIES:
> :ID:   978-84-362-7195-9
> :END:
> ...
> A “comment line” starts with a hash character (#) [n:102@978-84-362-7195-9] 
> and either a whitespace character or the immediate end of the line.
> ...
>
>
> ** Notes in file B
> [[id:978-84-362-7195-9]]: Link to heading in file A
>
> [n:102@978-84-362-7195-9]: Link to an exact point in file A. Where the point 
> is defined by the LABEL 102, and the file can be find thanks to the ID 
> 978-84-362-7195-9

I am a bit confused.
Do you propose footnotes to have definition in different file? Or do you
want a link to arbitrary point in different file?

For footnotes, we will need to arrange export to search the definition
and include it into the exported file, while links have different set of
requirements.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at