Re: [BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-17 Thread Visuwesh
[திங்கள் ஜூன் 17, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>>>> - (type (assoc (plist-get params :plot-type)
>>>> -  org-plot/preset-plot-types))
>>>> + (type (cdr (assoc (plist-get params :plot-type)
>>>> +   org-plot/preset-plot-types)))
>>>> gnuplot-script)
>>>
>>> This may break the existing customization.
>>> Later in the function, TYPE is used as an argument for
>>> `org-plot/gnuplot-term-extra' and `org-plot/gnuplot-script-preamble'.
>>> Some users may have these two custom options adjusted to the older
>>> calling convention.
>>>
>>> To not break things, we should pass the full `assoc' to these functions.
>>
>> If you meant org-plot/gnuplot-script eventually calling these functions,
>> then I don't see how the above change will break things.  Even in
>> org-plot/gnuplot-script, TYPE passed to both these user options are
>>
>> (let* ((type-name (plist-get params :plot-type))
>>(type (cdr (assoc type-name org-plot/preset-plot-types
>>
>> so there should be no harm done by the above change since TYPE is not an
>> argument taken by org-plot/gnuplot-script.
>
> Agree. I accidentally moved away from the function that is actually
> being changed to org-plot/gnuplot-script that has nothing to do with
> TYPE binding you are changing in the patch.
>
> So, your code is ok here.

Thanks, so please find attached.

>From 9755ccb636ab8e1d855bbc386bc6bab2203a2cd5 Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Tue, 18 Jun 2024 10:39:27 +0530
Subject: [PATCH] org-plot: Respect parameters given in
 `org-plot/preset-plot-types'

* org-plot.el (org-plot/gnuplot-script-preamble)
(org-plot/gnuplot-term-extra): Explain what "plot type" means.
(org-plot/preset-plot-types): Fix docstring and correct the lambda
argument order for the 'grid' plot type.
(org-plot/gnuplot): Merge the parameters given in
`org-plot/preset-plot-types' and the #+PLOT line to ensure the former
is respected everywhere.

Reported-by: Visuwesh 
Link: https://orgmode.org/list/87cypbjw50@gmail.com
---
 lisp/org-plot.el | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 83483b2..b436613 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -302,9 +302,10 @@ (defgroup org-plot nil
 (defcustom org-plot/gnuplot-script-preamble ""
   "String of function to be inserted before the gnuplot plot command is run.
 
-Note that this is in addition to, not instead of other content generated in
-`org-plot/gnuplot-script'.  If a function, it is called with the plot type as
-the argument, and must return a string to be used."
+Note that this is in addition to, not instead of other content generated
+in `org-plot/gnuplot-script'.  If a function, it is called with the
+parameters used by the current plot type (see
+`org-plot/preset-plot-types'), and must return a string to be used."
   :group 'org-plot
   :type '(choice string function))
 
@@ -349,7 +350,7 @@ (defcustom org-plot/preset-plot-types
 (grid :plot-cmd "splot"
 	  :plot-pre (lambda (_table _data-file _num-cols params _plot-str)
 		  (if (plist-get params :map) "set pm3d map" "set map"))
-	  :data-dump (lambda (table data-file params _num-cols)
+	  :data-dump (lambda (table data-file _num-cols params)
 		   (let ((y-labels (org-plot/gnuplot-to-grid-data
 	table data-file params)))
 			 (when y-labels (plist-put params :ylabels y-labels
@@ -391,8 +392,8 @@ (defcustom org-plot/preset-plot-types
 - :data-dump - Function to dump the table to a datafile for ease of
   use.
 
-  Accepts lambda function.  Default lambda body:
-  (org-plot/gnuplot-to-data table data-file params)
+  Accepts function with arguments:
+  (table data-file num-cols params)
 
 - :plot-pre - Gnuplot code to be inserted early into the script, just
   after term and output have been set.
@@ -541,7 +542,8 @@ (defcustom org-plot/gnuplot-term-extra ""
   "String or function which provides the extra term options.
 E.g. a value of \"size 1050,650\" would cause
 \"set term ... size 1050,650\" to be used.
-If a function, it is called with the plot type as the argument."
+If a function, it is called with the parameters used by the current plot
+type, see `org-plot/preset-plot-types'."
   :group 'org-plot
   :type '(choice string function))
 
@@ -678,8 +680,8 @@ (defun org-plot/gnuplot ( params)
 		tbl))
 	   (num-cols (length (if (eq (nth 0 table) 'hline) (nth 1 table)
 			   (nth 0 table
-	   (type (assoc (plist-get params :plot-type)
-			org-plot/preset-plot-types))
+	   (type (cdr (assoc (plist-get params :plot-type

Re: [BUG/FR] org-plot: replot on resize [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-16 Thread Visuwesh
[சனி ஜூன் 15, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>>> So, you can set DATA to (list (or dump-func 'org-plot/gnuplot-to-data) 
>>> table num-cols params)
>>
>> Done in the attached patch.
>
> Thanks!
>
>>;; Dump table to datafile
>> -  (let ((dump-func (plist-get type :data-dump)))
>> +  (let* ((dump-func (plist-get type :data-dump)))
>
> Why let*?

Oops, leftover change from a previous iteration of the patch.  Now
fixed.

>> +(setq data-file (org-babel-temp-stable-file
>> + (list (or dump-func 'org-plot/gnuplot-to-data)
>> +   table num-cols params)
>> + "org-plot"))
>
> Please add in-code comment explaining why we need 
> `org-babel-temp-stable-file'.

Now done.

>From a922946b3965e117dc3bbbe5a4f3c67dcc832d68 Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Sat, 15 Jun 2024 10:25:19 +0530
Subject: [PATCH] org-plot: Make data-file stable for replot-on-resize

* lisp/org-plot.el (org-plot/gnuplot): Use a stable data-file to make
replot-on-resize in GUI terminals work.

Reported-by: Visuwesh 
Link: https://orgmode.org/list/87mso7sl6g@gmail.com
---
 lisp/org-plot.el | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 283d993..83483b2 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -662,8 +662,7 @@ (defun org-plot/gnuplot ( params)
   (looking-at "[[:space:]]*#\\+"))
 (setf params (org-plot/collect-options params
 ;; collect table and table information
-(let* ((data-file (make-temp-file "org-plot"))
-   (table (let ((tbl (save-excursion
+(let* ((table (let ((tbl (save-excursion
(org-plot/goto-nearest-table)
(org-table-to-lisp
 		(when (pcase (plist-get params :transpose)
@@ -681,12 +680,11 @@ (defun org-plot/gnuplot ( params)
 			   (nth 0 table
 	   (type (assoc (plist-get params :plot-type)
 			org-plot/preset-plot-types))
-   gnuplot-script)
+   gnuplot-script data-file)
 
   (unless type
 	(user-error "Org-plot type `%s' is undefined" (plist-get params :plot-type)))
 
-  (run-with-idle-timer 0.1 nil #'delete-file data-file)
   (when (eq (cadr table) 'hline)
 	(setf params
 	  (plist-put params :labels (car table))) ; headers to labels
@@ -697,6 +695,12 @@ (defun org-plot/gnuplot ( params)
 			(setf params (org-plot/collect-options params
   ;; Dump table to datafile
   (let ((dump-func (plist-get type :data-dump)))
+;; Use a stable temporary file to ensure that 'replot' upon
+;; resizing a GUI gnuplot terminal window works.
+(setq data-file (org-babel-temp-stable-file
+ (list (or dump-func 'org-plot/gnuplot-to-data)
+   table num-cols params)
+ "org-plot"))
 (if dump-func
 	(funcall dump-func table data-file num-cols params)
 	  (org-plot/gnuplot-to-data table data-file params)))
-- 
2.43.0



Re: [BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-16 Thread Visuwesh
[சனி ஜூன் 15, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> Sorry for the noise, I copied the wrong link in the commit message.
>> Please see attached instead.
>
> Thanks!
> I have some comments.
>
>> -   (type (assoc (plist-get params :plot-type)
>> -org-plot/preset-plot-types))
>> +   (type (cdr (assoc (plist-get params :plot-type)
>> + org-plot/preset-plot-types)))
>> gnuplot-script)
>
> This may break the existing customization.
> Later in the function, TYPE is used as an argument for
> `org-plot/gnuplot-term-extra' and `org-plot/gnuplot-script-preamble'.
> Some users may have these two custom options adjusted to the older
> calling convention.
>
> To not break things, we should pass the full `assoc' to these functions.

If you meant org-plot/gnuplot-script eventually calling these functions,
then I don't see how the above change will break things.  Even in
org-plot/gnuplot-script, TYPE passed to both these user options are

(let* ((type-name (plist-get params :plot-type))
   (type (cdr (assoc type-name org-plot/preset-plot-types

so there should be no harm done by the above change since TYPE is not an
argument taken by org-plot/gnuplot-script.

> Also, while you are at it, may your please clarify what TYPE means in
> the docstrings of `org-plot/gnuplot-term-extra' and
> `org-plot/gnuplot-script-preamble'?

OK.

>>  (setf params (org-plot/collect-options params
>> +  (setq params (org-combine-plists type params))
>
> May you also drop a short comment in the code that explains what this
> line does?

I will send an updated patch once my confusion is cleared.



Re: [BUG/FR] org-plot: replot on resize [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-14 Thread Visuwesh
[வெள்ளி ஜூன் 14, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>>>> This is more of a FR than a bug but it would be nice to have working
>>>> replot-on-resize when the gnuplot terminal is qt, x11, etc.  To have
>>>> this functional, the data-file needs to be not deleted.
>>>
>>> It should be doable.
>>> We can simply use `org-babel-temp-stable-file' and leave cleaning up to
>>> `org-babel-remove-temporary-stable-directory'.
>>
>> The data writing functions themselves require a filename so the file
>> content cannot be used as DATA to org-babel-temp-stable-file.  What
>> should be DATA instead? (list table params)?
>
> All the things that contribute to what is written to the data file:
>
> ;; Dump table to datafile
>   (let ((dump-func (plist-get type :data-dump)))
> (if dump-func
>   (funcall dump-func table data-file num-cols params)
> (org-plot/gnuplot-to-data table data-file params)))
>
> So, you can set DATA to (list (or dump-func 'org-plot/gnuplot-to-data) table 
> num-cols params)

Done in the attached patch.

>From 0b81eb9da94cdf311bf54748b03d33a550d431cd Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Sat, 15 Jun 2024 10:25:19 +0530
Subject: [PATCH] org-plot: Make data-file stable for replot-on-resize

* lisp/org-plot.el (org-plot/gnuplot): Use a stable data-file to make
replot-on-resize in GUI terminals work.

Reported-by: Visuwesh 
Link: https://orgmode.org/list/87mso7sl6g@gmail.com
---
 lisp/org-plot.el | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 283d993..8adfbc8 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -662,8 +662,7 @@ (defun org-plot/gnuplot ( params)
   (looking-at "[[:space:]]*#\\+"))
 (setf params (org-plot/collect-options params
 ;; collect table and table information
-(let* ((data-file (make-temp-file "org-plot"))
-   (table (let ((tbl (save-excursion
+(let* ((table (let ((tbl (save-excursion
(org-plot/goto-nearest-table)
(org-table-to-lisp
 		(when (pcase (plist-get params :transpose)
@@ -681,12 +680,11 @@ (defun org-plot/gnuplot ( params)
 			   (nth 0 table
 	   (type (assoc (plist-get params :plot-type)
 			org-plot/preset-plot-types))
-   gnuplot-script)
+   gnuplot-script data-file)
 
   (unless type
 	(user-error "Org-plot type `%s' is undefined" (plist-get params :plot-type)))
 
-  (run-with-idle-timer 0.1 nil #'delete-file data-file)
   (when (eq (cadr table) 'hline)
 	(setf params
 	  (plist-put params :labels (car table))) ; headers to labels
@@ -696,7 +694,11 @@ (defun org-plot/gnuplot ( params)
   (looking-at "[[:space:]]*#\\+"))
 			(setf params (org-plot/collect-options params
   ;; Dump table to datafile
-  (let ((dump-func (plist-get type :data-dump)))
+  (let* ((dump-func (plist-get type :data-dump)))
+(setq data-file (org-babel-temp-stable-file
+ (list (or dump-func 'org-plot/gnuplot-to-data)
+   table num-cols params)
+ "org-plot"))
 (if dump-func
 	(funcall dump-func table data-file num-cols params)
 	  (org-plot/gnuplot-to-data table data-file params)))
-- 
2.43.0



Re: [BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-13 Thread Visuwesh
[வியாழன் ஜூன் 13, 2024] Visuwesh wrote:

> [புதன் ஜூன் 12, 2024] Ihor Radchenko wrote:
>
>> Visuwesh  writes:
>>
>>>> I do not think that it is right.
>>>> AFAIU, the idea is that `org-plot/preset-plot-types' provides some
>>>> default options, but the user can overwrite these defaults in the #+PLOT
>>>> line. What you propose will disregard the values of
>>>>
>>>>  :set :line :map :title :file :ind :timeind :timefmt :textind
>>>>  :deps :labels :xlabels :ylabels :xmin :xmax :ymin :ymax :ticks
>>>>
>>>> if they are customized by user in `org-plot/preset-plot-types'.
>>>
>>> I don't follow your conclusion since this change will only affect the
>>> value of :check-ind-type leaving the rest of the settings unaffected.
>>
>> My point is that we will eventually need to merge TYPE and PARAMS to
>> fix another bug - `org-plot/preset-plot-types' options like :set, :line,
>> etc being ignored. So, instead of patching the way you proposed, we can
>> merge TYPE and PARAMS into PARAMS, making the existing (plist-get params
>> :check-ind-type) working.
>>
>> In other words, org-plot's handling of parameters is very broken
>> now. There is more than one bug lurking there, and it may be more
>> productive to fix things together.
>>
>> You solution will, of course, work, but only for this specific bug you
>> described; not for other.
>
> OK, thanks for the explanation.  I was unaware of the issue as I didn't
> read the code closely enough.  What about the attached patch?

Sorry for the noise, I copied the wrong link in the commit message.
Please see attached instead.

>From 2a153a5bc015b0e970ecde39fd2edbb515261349 Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Thu, 13 Jun 2024 12:33:49 +0530
Subject: [PATCH] org-plot: Respect parameters given in
 `org-plot/preset-plot-types'

* lisp/org-plot.el (org-plot/preset-plot-types): Fix docstring and
correct the lambda argument order for the 'grid' plot type.
(org-plot/gnuplot): Merge the parameters given in
`org-plot/preset-plot-types' and the #+PLOT line to ensure the former
is respected everywhere.

Reported-by: Visuwesh 
Link: https://orgmode.org/list/87cypbjw50@gmail.com
---
 lisp/org-plot.el | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 283d993..6d53830 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -349,7 +349,7 @@ (defcustom org-plot/preset-plot-types
 (grid :plot-cmd "splot"
 	  :plot-pre (lambda (_table _data-file _num-cols params _plot-str)
 		  (if (plist-get params :map) "set pm3d map" "set map"))
-	  :data-dump (lambda (table data-file params _num-cols)
+	  :data-dump (lambda (table data-file _num-cols params)
 		   (let ((y-labels (org-plot/gnuplot-to-grid-data
 	table data-file params)))
 			 (when y-labels (plist-put params :ylabels y-labels
@@ -391,8 +391,8 @@ (defcustom org-plot/preset-plot-types
 - :data-dump - Function to dump the table to a datafile for ease of
   use.

-  Accepts lambda function.  Default lambda body:
-  (org-plot/gnuplot-to-data table data-file params)
+  Accepts lambda function with arguments:
+  (table data-file num-cols params)

 - :plot-pre - Gnuplot code to be inserted early into the script, just
   after term and output have been set.
@@ -679,8 +679,8 @@ (defun org-plot/gnuplot ( params)
 		tbl))
 	   (num-cols (length (if (eq (nth 0 table) 'hline) (nth 1 table)
 			   (nth 0 table
-	   (type (assoc (plist-get params :plot-type)
-			org-plot/preset-plot-types))
+	   (type (cdr (assoc (plist-get params :plot-type)
+			 org-plot/preset-plot-types)))
gnuplot-script)

   (unless type
@@ -695,6 +695,7 @@ (defun org-plot/gnuplot ( params)
   (save-excursion (while (and (equal 0 (forward-line -1))
   (looking-at "[[:space:]]*#\\+"))
 			(setf params (org-plot/collect-options params
+  (setq params (org-combine-plists type params))
   ;; Dump table to datafile
   (let ((dump-func (plist-get type :data-dump)))
 (if dump-func
--
2.43.0


Re: [BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-13 Thread Visuwesh
[புதன் ஜூன் 12, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>>> I do not think that it is right.
>>> AFAIU, the idea is that `org-plot/preset-plot-types' provides some
>>> default options, but the user can overwrite these defaults in the #+PLOT
>>> line. What you propose will disregard the values of
>>>
>>>  :set :line :map :title :file :ind :timeind :timefmt :textind
>>>  :deps :labels :xlabels :ylabels :xmin :xmax :ymin :ymax :ticks
>>>
>>> if they are customized by user in `org-plot/preset-plot-types'.
>>
>> I don't follow your conclusion since this change will only affect the
>> value of :check-ind-type leaving the rest of the settings unaffected.
>
> My point is that we will eventually need to merge TYPE and PARAMS to
> fix another bug - `org-plot/preset-plot-types' options like :set, :line,
> etc being ignored. So, instead of patching the way you proposed, we can
> merge TYPE and PARAMS into PARAMS, making the existing (plist-get params
> :check-ind-type) working.
>
> In other words, org-plot's handling of parameters is very broken
> now. There is more than one bug lurking there, and it may be more
> productive to fix things together.
>
> You solution will, of course, work, but only for this specific bug you
> described; not for other.

OK, thanks for the explanation.  I was unaware of the issue as I didn't
read the code closely enough.  What about the attached patch?

>From 2a153a5bc015b0e970ecde39fd2edbb515261349 Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Thu, 13 Jun 2024 12:33:49 +0530
Subject: [PATCH] org-plot: Respect parameters given in
 `org-plot/preset-plot-types'

* lisp/org-plot.el (org-plot/preset-plot-types): Fix docstring and
correct the lambda argument order for the 'grid' plot type.
(org-plot/gnuplot): Merge the parameters given in
`org-plot/preset-plot-types' and the #+PLOT line to ensure the former
is respected everywhere.

Reported-by: Visuwesh 
Link: https://orgmode.org/list/87edbu4kdh@gmail.com
---
 lisp/org-plot.el | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 283d993..6d53830 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -349,7 +349,7 @@ (defcustom org-plot/preset-plot-types
 (grid :plot-cmd "splot"
 	  :plot-pre (lambda (_table _data-file _num-cols params _plot-str)
 		  (if (plist-get params :map) "set pm3d map" "set map"))
-	  :data-dump (lambda (table data-file params _num-cols)
+	  :data-dump (lambda (table data-file _num-cols params)
 		   (let ((y-labels (org-plot/gnuplot-to-grid-data
 	table data-file params)))
 			 (when y-labels (plist-put params :ylabels y-labels
@@ -391,8 +391,8 @@ (defcustom org-plot/preset-plot-types
 - :data-dump - Function to dump the table to a datafile for ease of
   use.
 
-  Accepts lambda function.  Default lambda body:
-  (org-plot/gnuplot-to-data table data-file params)
+  Accepts lambda function with arguments:
+  (table data-file num-cols params)
 
 - :plot-pre - Gnuplot code to be inserted early into the script, just
   after term and output have been set.
@@ -679,8 +679,8 @@ (defun org-plot/gnuplot ( params)
 		tbl))
 	   (num-cols (length (if (eq (nth 0 table) 'hline) (nth 1 table)
 			   (nth 0 table
-	   (type (assoc (plist-get params :plot-type)
-			org-plot/preset-plot-types))
+	   (type (cdr (assoc (plist-get params :plot-type)
+			 org-plot/preset-plot-types)))
gnuplot-script)
 
   (unless type
@@ -695,6 +695,7 @@ (defun org-plot/gnuplot ( params)
   (save-excursion (while (and (equal 0 (forward-line -1))
   (looking-at "[[:space:]]*#\\+"))
 			(setf params (org-plot/collect-options params
+  (setq params (org-combine-plists type params))
   ;; Dump table to datafile
   (let ((dump-func (plist-get type :data-dump)))
 (if dump-func
-- 
2.43.0



Re: [BUG/FR] org-plot: replot on resize [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-13 Thread Visuwesh
[செவ்வாய் ஜூன் 04, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> This is more of a FR than a bug but it would be nice to have working
>> replot-on-resize when the gnuplot terminal is qt, x11, etc.  To have
>> this functional, the data-file needs to be not deleted.
>
> It should be doable.
> We can simply use `org-babel-temp-stable-file' and leave cleaning up to
> `org-babel-remove-temporary-stable-directory'.

The data writing functions themselves require a filename so the file
content cannot be used as DATA to org-babel-temp-stable-file.  What
should be DATA instead? (list table params)?



Re: [BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-10 Thread Visuwesh
Ping.  Can you answer my questions, Ihor, so that I may prepare a patch
accordingly?

[வெள்ளி மே 24, 2024] Visuwesh wrote:

> [வெள்ளி மே 24, 2024] Ihor Radchenko wrote:
>
>> Visuwesh  writes:
>>
>>> Unless I misunderstood the code, the line
>>>
>>>   ;; Check type of ind column (timestamp? text?)
>>>   (when (plist-get params :check-ind-type)
>>>
>>> should be
>>>
>>>   ;; Check type of ind column (timestamp? text?)
>>>   (when (plist-get (cdr type) :check-ind-type)
>>>
>>> because (1) org-plot/collect-options only adds a select number of
>>> keywords to the plist and :check-ind-type is not a part of the select
>>> members, and (2) org-plot/gnuplot is never called with a non-nil value
>>> for the optional argument PARAMS in tree.
>>
>> I do not think that it is right.
>> AFAIU, the idea is that `org-plot/preset-plot-types' provides some
>> default options, but the user can overwrite these defaults in the #+PLOT
>> line. What you propose will disregard the values of
>>
>>  :set :line :map :title :file :ind :timeind :timefmt :textind
>>  :deps :labels :xlabels :ylabels :xmin :xmax :ymin :ymax :ticks
>>
>> if they are customized by user in `org-plot/preset-plot-types'.
>
> I don't follow your conclusion since this change will only affect the
> value of :check-ind-type so how would it affect the rest of the
> settings?
>
>> I believe that the right way to address the problem will be
>> `org-combine-plists' on the (1) org-plot/preset-plot-types; (2)
>> org-plot/gnuplot-default-options; (3) #+PLOT lines in the buffer.
>
> Looking at the definition of org-plot/add-options-to-plist and the Info
> manual, I am not sure if :check-ind-type is supposed to be customised by
> the PLOT line.  It seems to be more of an internal setting.  If you
> agree to this, I can change the check to
>
> (when (or (plist-get type :check-ind-type) (plist-get params 
> :check-ind-type))
>
> to heed the value of :check-ind-type in org-plot/gnuplot-default-options
> (since PARAMS has the default values included earlier in the defun).
>
>>> [...]
>>> The other code smell I see is that the function checks for the PLOT line
>>> twice.  Once near the beginning of the function, and once just after the
>>> cleaning up of hline.  Is this simply an oversight?
>>
>> It is kinda intentional, but broken.
>>
>> Historically, users can put #+PLOT lines _after_ the table.
>> However, after refactoring org-table.el, this is no longer working.
>> See https://list.orgmode.org/orgmode/87o7a0p9ba.fsf@localhost/
>
> OK, I will leave the check in then.
>
>>> Coming to the grid example, the doc-string of org-plot/preset-plot-types
>>> options says:
>>>
>>> - :data-dump - Function to dump the table to a datafile for ease of
>>>   use.
>>>
>>>   Accepts lambda function.  Default lambda body:
>>>   (org-plot/gnuplot-to-data table data-file params)
>>>
>>> but in fact, org-plot/gnuplot passes one more argument to the :data-dump
>>> function:
>>>
>>>   ;; Dump table to datafile
>>>   (let ((dump-func (plist-get type :data-dump)))
>>> (if dump-func
>>> (funcall dump-func table data-file num-cols params)
>>>   (org-plot/gnuplot-to-data table data-file params)))
>>>
>>> but here's the catch: the :data-dump function in the grid option expects
>>> the order
>>>
>>> (lambda (table data-file params _num-cols)
>>>
>>> which breaks things down the line.  What should be the actual order
>>> here?  I looked at the history of those lines briefly using C-x v h but
>>> I don't have the time to look into it properly to decide on the actual
>>> argument order.
>>
>> The best order is de-facto calling convention in the code:
>>
>> (funcall dump-func table data-file num-cols params)
>>
>> The docstring and the default value should be fixed accordingly.
>
> OK, will do this in a future patch.



Re: [ANN] Org mode 9.7 is out

2024-06-06 Thread Visuwesh
[புதன் ஜூன் 05, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> BTW, we might have similar problems in Windows too.  See this thread in
>> emacs-devel when yank-media was initially added:
>> https://yhetil.org/emacs-devel/837ddk9tc8@gnu.org
>
> Looking at that thread, I see
> https://yhetil.org/emacs-devel/yz18w18vybg7cb%...@idiocy.org/
>
> +  /* Dictionary for looking up NS types from MIME types, and vice versa.  */
> +  typeLookup
> += [NSDictionary
> +   dictionaryWithObjectsAndKeys:
> + @"text/plain",NSPasteboardTypeURL,
> +#if NS_USE_NSPasteboardTypeFileURL
> + @"text/plain",NSPasteboardTypeFileURL,
> +#else
> + @"text/plain",NSFilenamesPboardType,
> +#endif
> + @"text/html", NSPasteboardTypeHTML,
> + @"text/plain",NSPasteboardTypeMultipleTextSelection,
> + @"application/pdf",   NSPasteboardTypePDF,
> + @"image/png", NSPasteboardTypePNG,
> + @"application/rtf",   NSPasteboardTypeRTF,
> + @"application/rtfd",  NSPasteboardTypeRTFD,
> + @"STRING",NSPasteboardTypeString,
> + @"text/plain",NSPasteboardTypeTabularText,
> + @"image/tiff",NSPasteboardTypeTIFF,
> + nil];
>
> For images, only image/png and image/tiff are listed for some reason. No
> jpeg. (and no jpeg in the spec at
> https://developer.apple.com/documentation/appkit/nspasteboardtype)
>
> I suspect that image/tiff entry in the clipboard is garbled by Emacs.
> We may want to report this as a bug.
>
> We may also need to request a feature to support clipboard on MacOS
> better. Using the same example image.

Thanks for the analysis.  Given that Alan says GNUStep cannot handle
non-text clipboard items, I cannot propose anything myself.  It would be
nice if a Mac user can write a report and send it to the Emacs
developers.  Perhaps Juergen can do it?

There was a bug report about yank-media failing in Mac yesterday or
thereabouts so I think the clipboard situation in Mac has a lot to
improve.  Hopefully with Org's yank-media support the situation will
improve.



Re: [ANN] Org mode 9.7 is out

2024-06-05 Thread Visuwesh
[புதன் ஜூன் 05, 2024] Juergen Fenn wrote:

> Am 03.06.24 um 07:06 Uhr schrieb Visuwesh:
>> [ஞாயிறு ஜூன் 02, 2024] Juergen Fenn wrote:
>>> [...]
>>> I'm afraid I forgot to mention that I don't get prompted, and I did not
>>> copy the image from my webbrowser. Rather, I downloaded the jpg file
>>> over Europeana's proxy from Finnish National Library and then copied
>>> this one with Command-c in Finder (the macOS file manager) from local
>>> system SSD. I do not understand how the tiff comes in here. But is is
>>> there in the data folder Org created. I tried to open it in Preview, I
>>> even changed the file ending to .jpg, but I cannot open it. The tiff
>>> file seems to be corrupt.
>>>
>>
>> Please tell what is shown in the *Completions* buffer when you do M-x
>> yank-media-types RET after you copy the image to the clipboard.  I
>> suspect the problem is with the regexp used to detect the mime-type.
>>
>
> Sorry for my late reply. I have updated to Org 9.7.2 in the meanwhile.
>
> M-x yank-media-types RET yields:
>
> Yank type:
> clipboard:image/tiff
> clipboard:STRING
> clipboard:text/plain

I'm afraid there's nothing much we can do.  IIUC, you copy the file from
a file manager, so Org expects clipboard to be something like

Possible completions are:
clipboard:x-special/gnome-copied-files
primary:...

where clipboard:x-special/gnome-copied-files gives

copy
file:///home/viz/tmp/2-gnus_stipple.png

but given there's neither image/jpeg nor a special type like the above,
Org's yank-media copies the image/tiff data (the regexp used by Org
looks for mime-types that match the regexp "image/.*").
I am guessing clipboard:text/plain contains the link to the file, am I
right?  But this feels fragile to rely on.

What happens when you copy multiple images to the clipboard from the
file manager?  Is there a difference in yank-media-types' output?  What
if you copy a non-image file to the clipboard? Say a PDF file.

I don't have access to a Mac but if you can find documentation on how
Finder puts the relevant data in the clipboard, that would be useful.
[ In Linux, you expect the x-special/gnome-copied-files or somesuch
  TARGET.  ]

BTW, we might have similar problems in Windows too.  See this thread in
emacs-devel when yank-media was initially added:
https://yhetil.org/emacs-devel/837ddk9tc8@gnu.org

> M-x yank-media RET still inserts an attachment with a tiff file that I
> cannot open in Preview.

Given the above, I hope you understand why this happens.

HTH.



Re: [ANN] Org mode 9.7 is out

2024-06-02 Thread Visuwesh
[ஞாயிறு ஜூன் 02, 2024] Juergen Fenn wrote:

> Am 02.06.24 um 22:11 Uhr schrieb Ihor Radchenko:
>> Juergen Fenn  writes:
>>
 Org normally asks you what format to insert, if multiple formats are
 available from clipboard.
>>> ...
>>> Well, the image I used is this one. It was available because I had
>>> downloaded it the other day:
>>>
>>> https://www.europeana.eu/fr/item/2021012/_42FFE0B5C39B7F9819D6D3692B2F4154
>>>
>>> The format is jpg. I have no idea why I get a tiff attachment when I try
>>> to include a local jpg file. Maybe the macOS clipboard offers several
>>> formats and Emacs/Org choses one option because it is offered first or
>>> for some other reason? Or some kind of conversion plays into this on the
>>> system level when copying to Emacs? Or there is something wrong or
>>> unsusual with the jpg file, perhaps it was a tiff file in the first
>>> place, later converted to jpg. I do not know.
>>
>> Even Linux clipboard offers several formats if I copy from browser.
>> After M-x yank-media, I get "Several types, available, choose one:"
>> prompt, with options to choose from png/pbm/xbm/xpm/jpeg format. I
>> guess it is also tiff in your case. Just choose another format in that
>> prompt.
>
> I'm afraid I forgot to mention that I don't get prompted, and I did not
> copy the image from my webbrowser. Rather, I downloaded the jpg file
> over Europeana's proxy from Finnish National Library and then copied
> this one with Command-c in Finder (the macOS file manager) from local
> system SSD. I do not understand how the tiff comes in here. But is is
> there in the data folder Org created. I tried to open it in Preview, I
> even changed the file ending to .jpg, but I cannot open it. The tiff
> file seems to be corrupt.
>

Please tell what is shown in the *Completions* buffer when you do M-x
yank-media-types RET after you copy the image to the clipboard.  I
suspect the problem is with the regexp used to detect the mime-type.



[BUG/FR] org-plot: replot on resize [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-06-02 Thread Visuwesh


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


This is more of a FR than a bug but it would be nice to have working
replot-on-resize when the gnuplot terminal is qt, x11, etc.  To have
this functional, the data-file needs to be not deleted.

Emacs  : GNU Emacs 30.0.50 (build 8, x86_64-pc-linux-gnu, X toolkit, cairo 
version 1.18.0, Xaw scroll bars)
 of 2024-05-07
Package: Org mode version 9.7-pre (N/A @ 
/home/viz/lib/emacs/straight/build/org/)



Re: [Pre-PATCH] Overhaul of the LaTeX preview system

2024-05-30 Thread Visuwesh
[ Sorry, I do not have a better starting point for this.  ]

After updating Latex, I got the message:

Creating LaTeX preview images failed (exit code 252). Please see *Org 
Preview LaTeX Output* for details

which corresponds to

RUNNING: latex -interaction nonstopmode -output-directory /tmp/ 
/home/viz/doc/uni/notes/org-tex-KByBIT.tex
This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2025/dev/Debian) 
(preloaded 
format=/home/viz/.cache/org-persist/70/4b50e3-c1f1-4ed9-be3a-acf259bf6d3d-54035ced5d211d19e0eec7be4671c146)
 restricted \write18 enabled.
---! 
/home/viz/.cache/org-persist/70/4b50e3-c1f1-4ed9-be3a-acf259bf6d3d-54035ced5d211d19e0eec7be4671c146.fmt
 made by different executable version, strings are different
(Fatal format file error; I'm stymied)

Would it be possible to give a more informative message for this case?
It is not a showstopper since the error message by pdfTeX is informative
enough but something more informative from Org would be nice regardless.



Re: [BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-05-24 Thread Visuwesh
[வெள்ளி மே 24, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> Unless I misunderstood the code, the line
>>
>>   ;; Check type of ind column (timestamp? text?)
>>   (when (plist-get params :check-ind-type)
>>
>> should be
>>
>>   ;; Check type of ind column (timestamp? text?)
>>   (when (plist-get (cdr type) :check-ind-type)
>>
>> because (1) org-plot/collect-options only adds a select number of
>> keywords to the plist and :check-ind-type is not a part of the select
>> members, and (2) org-plot/gnuplot is never called with a non-nil value
>> for the optional argument PARAMS in tree.
>
> I do not think that it is right.
> AFAIU, the idea is that `org-plot/preset-plot-types' provides some
> default options, but the user can overwrite these defaults in the #+PLOT
> line. What you propose will disregard the values of
>
>  :set :line :map :title :file :ind :timeind :timefmt :textind
>  :deps :labels :xlabels :ylabels :xmin :xmax :ymin :ymax :ticks
>
> if they are customized by user in `org-plot/preset-plot-types'.

I don't follow your conclusion since this change will only affect the
value of :check-ind-type leaving the rest of the settings unaffected.

> I believe that the right way to address the problem will be
> `org-combine-plists' on the (1) org-plot/preset-plot-types; (2)
> org-plot/gnuplot-default-options; (3) #+PLOT lines in the buffer.

Looking at the definition of org-plot/add-options-to-plist and the Info
manual, I am not sure if :check-ind-type is supposed to be customised by
the PLOT line.  It seems to be more of an internal setting.  If you
agree to this, I can change the check to

(when (or (plist-get type :check-ind-type) (plist-get params 
:check-ind-type))

to heed the value of :check-ind-type in org-plot/gnuplot-default-options
(since PARAMS has the default values included earlier in the defun).

>> [...]
>> The other code smell I see is that the function checks for the PLOT line
>> twice.  Once near the beginning of the function, and once just after the
>> cleaning up of hline.  Is this simply an oversight?
>
> It is kinda intentional, but broken.
>
> Historically, users can put #+PLOT lines _after_ the table.
> However, after refactoring org-table.el, this is no longer working.
> See https://list.orgmode.org/orgmode/87o7a0p9ba.fsf@localhost/

OK, I will leave the check in then.

>> Coming to the grid example, the doc-string of org-plot/preset-plot-types
>> options says:
>>
>> - :data-dump - Function to dump the table to a datafile for ease of
>>   use.
>>
>>   Accepts lambda function.  Default lambda body:
>>   (org-plot/gnuplot-to-data table data-file params)
>>
>> but in fact, org-plot/gnuplot passes one more argument to the :data-dump
>> function:
>>
>>   ;; Dump table to datafile
>>   (let ((dump-func (plist-get type :data-dump)))
>> (if dump-func
>>  (funcall dump-func table data-file num-cols params)
>>(org-plot/gnuplot-to-data table data-file params)))
>>
>> but here's the catch: the :data-dump function in the grid option expects
>> the order
>>
>> (lambda (table data-file params _num-cols)
>>
>> which breaks things down the line.  What should be the actual order
>> here?  I looked at the history of those lines briefly using C-x v h but
>> I don't have the time to look into it properly to decide on the actual
>> argument order.
>
> The best order is de-facto calling convention in the code:
>
> (funcall dump-func table data-file num-cols params)
>
> The docstring and the default value should be fixed accordingly.

OK, will do this in a future patch.



[BUG] org-plot: Unable to use text xtics with type:2d (+ more) [9.7-pre (N/A @ /home/viz/lib/emacs/straight/build/org/)]

2024-05-24 Thread Visuwesh

Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


Consider the following table, and try to execute the PLOT line

#+PLOT: ind:1 deps:(3) type:2d with:lp
| Sede  | Max cites | H-index |
|---+---+-|
| Chile |257.72 |   21.39 |
| Leeds |165.77 |   19.68 |
| Sao Paolo | 71.00 |   11.50 |
| Stockholm |134.19 |   14.33 |
| Morelia   |257.56 |   17.67 |

and watch it fail (see the error message in the *gnuplot* buffer).
Although the 2d option in org-plot/preset-plot-types has :check-ind-type
set to a non-nil value, org-plot/gnuplot does not check the value of
:check-ind-type assigned in the 2d type given in the user-option.

Unless I misunderstood the code, the line

  ;; Check type of ind column (timestamp? text?)
  (when (plist-get params :check-ind-type)

should be

  ;; Check type of ind column (timestamp? text?)
  (when (plist-get (cdr type) :check-ind-type)

because (1) org-plot/collect-options only adds a select number of
keywords to the plist and :check-ind-type is not a part of the select
members, and (2) org-plot/gnuplot is never called with a non-nil value
for the optional argument PARAMS in tree.

BTW, the earlier check in the function for :data-dump should also fail
because

(plist-get (assoc 'grid org-plot/preset-plot-types) :data-dump) ;; => nil

but

(plist-get (cdr (assoc 'grid org-plot/preset-plot-types)) :data-dump) ;; => 
non-nil

where type ≡ (assoc 'grid org-plot/preset-plot-types) in
org-plot/gnuplot.

[ I cannot reproduce the grid example in worg's org-plot.org file, but
  even with the fix, I cannot reproduce it; more below.  ]

The other code smell I see is that the function checks for the PLOT line
twice.  Once near the beginning of the function, and once just after the
cleaning up of hline.  Is this simply an oversight?

Coming to the grid example, the doc-string of org-plot/preset-plot-types
options says:

- :data-dump - Function to dump the table to a datafile for ease of
  use.

  Accepts lambda function.  Default lambda body:
  (org-plot/gnuplot-to-data table data-file params)

but in fact, org-plot/gnuplot passes one more argument to the :data-dump
function:

  ;; Dump table to datafile
  (let ((dump-func (plist-get type :data-dump)))
(if dump-func
(funcall dump-func table data-file num-cols params)
  (org-plot/gnuplot-to-data table data-file params)))

but here's the catch: the :data-dump function in the grid option expects
the order

(lambda (table data-file params _num-cols)

which breaks things down the line.  What should be the actual order
here?  I looked at the history of those lines briefly using C-x v h but
I don't have the time to look into it properly to decide on the actual
argument order.

For now, I have attached a patch that fixes all the issues.  With the
patch, i can run the example covered in the bug report.  The grid
example given in worg passes but it doesn't look as expected.  I am not
sure what to blame here.

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 283d993..3be1b2f 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -679,8 +679,8 @@ (defun org-plot/gnuplot ( params)
 		tbl))
 	   (num-cols (length (if (eq (nth 0 table) 'hline) (nth 1 table)
 			   (nth 0 table
-	   (type (assoc (plist-get params :plot-type)
-			org-plot/preset-plot-types))
+	   (type (cdr (assoc (plist-get params :plot-type)
+			 org-plot/preset-plot-types)))
gnuplot-script)

   (unless type
@@ -691,17 +691,13 @@ (defun org-plot/gnuplot ( params)
 	(setf params
 	  (plist-put params :labels (car table))) ; headers to labels
 	(setf table (delq 'hline (cdr table ; clean non-data from table
-  ;; Collect options.
-  (save-excursion (while (and (equal 0 (forward-line -1))
-  (looking-at "[[:space:]]*#\\+"))
-			(setf params (org-plot/collect-options params
   ;; Dump table to datafile
   (let ((dump-func (plist-get type :data-dump)))
 (if dump-func
-	(funcall dump-func table data-file num-cols params)
+	(funcall dump-func table data-file params num-cols)
 	  (org-plot/gnuplot-to-data table data-file params)))
   ;; Check type of ind column (timestamp? text?)
-  (when (plist-get params :check-ind-type)
+  (when (plist-get type :check-ind-type)
 	(let* ((ind (1- (plist-get params :ind)))
 	   (ind-column (mapcar (lambda (row) (nth ind row)) table)))
 	  (cond ((< ind 0) nil) ; ind is implicit

Emacs  : GNU Emacs 30.0.50 (build 8, x86_64-pc-linux-gnu, X toolkit, cairo 
version 1.18.0, Xaw scroll bars)
 of 2024-05-07
Package: Org mode version 

Re: [BUG] ob-calc and decimal number in :var [9.7-pre (release_9.6.17-1446-g252971 @ /home/viz/lib/emacs/straight/build/org/)]

2024-05-02 Thread Visuwesh
[வியாழன் மே 02, 2024] Ihor Radchenko wrote:

> Ihor Radchenko  writes:
>
>>> #+BEGIN_SRC calc :var thetarot=1.3
>>>   1/thetarot
>>> #+END_SRC
>>>
>>> and witness the following error:
>>>
>>> Debugger entered--Lisp error: (wrong-type-argument listp 1.3)
>>>   nth(2 1.3)
>>
>> Confirmed.
>
> Fixed, on main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=dd12e9c76

Great, thanks!  Unfortunately, I couldn't find the time to find a proper
fix, thank you for your fix.



Re: [PATCH] Add support for tables in Calc src block :var

2024-03-30 Thread Visuwesh
[திங்கள் மார்ச் 18, 2024] Fraga, Eric wrote:

Good day, Eric!

> Thank you for this.  Potentially very useful.
>
> As you have managed to understand calc internals (to a much greater
> degrees than I have ever managed), do you know if there is any way to go
> the other way?  Specifically, I would love to make reference to calc
> variables, especially those defined using embedded calc, in org tables.

Can you please provide a minimal example for me to play around with?  I
realise I would like something like this too [*] but I don't know
concretely what this would/should look like.



[*] More specifically, I want to pass around src block evaluation
results in a table formula.



[BUG] ob-calc and decimal number in :var [9.7-pre (release_9.6.17-1446-g252971 @ /home/viz/lib/emacs/straight/build/org/)]

2024-03-28 Thread Visuwesh


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


In emacs -Q, try evaluating the source block

#+BEGIN_SRC calc :var thetarot=1.3
  1/thetarot
#+END_SRC

and witness the following error:

Debugger entered--Lisp error: (wrong-type-argument listp 1.3)
  nth(2 1.3)
  calc-div-fractions(1 1.3)
  math-div(1 1.3)
  math-mul-or-div(1 1.3 nil t)
  math-combine-prod(1 1.3 nil t t)
  math-simplify-one-divisor((1 1.3) (1.3))
  math-simplify-divisor((1 1.3) (1.3) nil t)
  math-simplify-divide((/ 1 1.3))
  #f(compiled-function (expr) #)((/ 1 1.3))
  math-simplify-step((/ 1 1.3))
  math-simplify((/ 1 1.3))
  calc-normalize-fancy((/ 1 1.3))
  calc-normalize((/ 1 1.3))
  math-evaluate-expr((/ 1 1.3))
  #f(compiled-function (line) #)("1/thetarot")
  mapc(#f(compiled-function (line) #) 
("1/thetarot"))
  org-babel-execute:calc("1/thetarot\11" ((:var thetarot . 1.3) 
(:colname-names) (:rowname-names) (:result-params "replace") (:result-type . 
value) (:results . "replace") (:exports . "code") (:session . "none") (:cache . 
"no") (:noweb . "no") (:hlines . "no") (:tangle . "no")))
  org-babel-execute-src-block(nil ("calc" "1/thetarot\11" ((:var thetarot . 
1.3) (:colname-names) (:rowname-names) (:result-params "replace") (:result-type 
. value) (:results . "replace") (:exports . "code") (:tangle . "no") (:hlines . 
"no") (:noweb . "no") (:cache . "no") (:session . "none")) "" nil 148 
"(ref:%s)"))
  org-ctrl-c-ctrl-c(nil)
  funcall-interactively(org-ctrl-c-ctrl-c nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
  command-execute(org-ctrl-c-ctrl-c)

This happens because the decimal number 1.3 is not in the format calc
expects.  A VERY DIRTY patch to do this is

diff --git a/lisp/ob-calc.el b/lisp/ob-calc.el
index f36df77ff..6ef09032a 100644
--- a/lisp/ob-calc.el
+++ b/lisp/ob-calc.el
@@ -111,7 +116,7 @@ EL is taken from the output of `math-read-exprs'."
   (if (and (eq 'var (car el)) (member (cadr el) org--var-syms))
  (progn
(calc-recall (cadr el))
-   (prog1 (calc-top 1)
+   (prog1 (math-read-exprs (format "%S" (calc-top 1)))
  (calc-pop 1)))
(mapcar #'org-babel-calc-maybe-resolve-var el))
 el))

but unfortunately, I don't have the time currently to polish this up.
If someone doesn't beat me to it, I will send a more polished+tested
patch by the beginning of May (if I get a lot of free time, I can try to
make one in the meanwhile).

Emacs  : GNU Emacs 30.0.50 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo 
version 1.18.0, Xaw scroll bars)
 of 2024-02-17
Package: Org mode version 9.7-pre (release_9.6.17-1446-g252971 @ 
/home/viz/lib/emacs/straight/build/org/)



Re: [PATCH] Add support for tables in Calc src block :var

2024-03-18 Thread Visuwesh
[திங்கள் மார்ச் 18, 2024] Fraga, Eric wrote:

> Thank you for this.  Potentially very useful.
>
> As you have managed to understand calc internals (to a much greater
> degrees than I have ever managed), do you know if there is any way to go
> the other way?  Specifically, I would love to make reference to calc
> variables, especially those defined using embedded calc, in org tables.

You give me far too credit: I merely placed an edebug trigger for
calc-push-list and used a simple-minded ' [1,2,3;4,5,6] RET to figure
out the vector format (then later I found the commentary).

If I get the time, I will try to look into your request.  Unfortunately,
I cannot promise anything since I am near the end of my semester making
me annoyingly busy.
[ I would like to make ob-calc turn matrices into tables in the result:
  like what ob-fortran and others already do.  ]

> Thanks again,
> eric



Re: [PATCH] Add support for tables in Calc src block :var

2024-03-16 Thread Visuwesh
[சனி மார்ச் 16, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> Subject: [PATCH] ob-calc.el: Add support for tables in Calc source block :var
>
> Thanks!
> Applied, onto main.
> I modified the patch to enable ob-calc tests by default.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=89b0773c3

Thanks!

>>> Would you mind using `org-test-with-temp-text' instead of
>>> `org-test-at-id' as much as possible? Otherwise, looking at tests like
>>
>> OK, I wasn't sure what test style to use since the README in testing/
>> does not talk about writing new tests.  Now I have adapted the tests to
>> use org-test-with-temp-text.
>
> Yeah. We do not have a dedicated style document for Org mode tests.



Re: [PATCH] Add support for tables in Calc src block :var

2024-03-16 Thread Visuwesh
[சனி மார்ச் 16, 2024] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> Attached patch adds support for passing tables as matrices (or vector)
>> to a Calc source block through the :var parameter.  There might be a
>> better way to do it than manually construct the data structure expected
>> by Calc for a matrix but given that it rarely sees changes in this area,
>> it shouldn't be a bother.
>> I also added tests for this feature, and other simple tests to ensure
>> everything works.  I checked that all the tests passed on my side.
>
> Thanks!
> Since you are adding a new feature, may you also add an entry to etc/ORG-NEWS?

Now done.

>> -   (calc-push-list (list (cdr pair)))
>> +   (let ((val (cdr pair)))
>> + (calc-push-list
>> +  (list (if (listp val)
>> +(cons 'vec
>> +  (if (null (cdr val))
>> +  (car val)
>> +(mapcar (lambda (x) (if (listp x) (cons 'vec x) 
>> x))
>> +val)))
>> +  val
>
> It would be nice to add code comments explaining the Calc's internal
> format. Ideally, with references to Calc's manual or source code.
> Otherwise, this code looks like black magic :)

I hope the comment I added in the attached patch is clear enough.

>> +++ b/testing/examples/ob-calc-test.org
>> @@ -0,0 +1,57 @@
>> +#+TITLE: Tests for ob-calc
>> +#+OPTIONS: ^:nil
>
> Thanks a lot for adding many tests!
> Would you mind using `org-test-with-temp-text' instead of
> `org-test-at-id' as much as possible? Otherwise, looking at tests like

OK, I wasn't sure what test style to use since the README in testing/
does not talk about writing new tests.  Now I have adapted the tests to
use org-test-with-temp-text.

>From 29962bc3ec33e1e25f83f153b681d49182368592 Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Sat, 16 Mar 2024 17:04:14 +0530
Subject: [PATCH] ob-calc.el: Add support for tables in Calc source block :var

A table with MxN dimensions is converted to a MxN matrix when given in
:var to a Calc source block.  A table with a single row is converted
to a vector (i.e., row vector).

* lisp/ob-calc.el (org-babel-execute-src-block:calc): Construct the
right data structure to pass tables as matrices to Calc.
* testing/lisp/test-ob-calc.el: Add tests for ob-calc, and this new
feature.
* etc/ORG-NEWS: Announce the feature.
---
 etc/ORG-NEWS |   7 +++
 lisp/ob-calc.el  |  14 -
 testing/lisp/test-ob-calc.el | 115 +++
 3 files changed, 135 insertions(+), 1 deletion(-)
 create mode 100644 testing/lisp/test-ob-calc.el

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index ca73f06e7..197d7503d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -1121,6 +1121,13 @@ Maxima's graphics packages (~draw~ or ~plot~); the default remains
 ~plot~.  The graphics terminal is now determined from the file-ending
 of the file-name set in the ~:file~ header argument.
 
+*** =ob-calc.el=: Support for tables in ~:var~
+
+=ob-calc= now supports tables in ~:var~.  They are converted to a
+matrix or a vector depending on the dimensionality of the table.  A
+table with a single row is converted to a vector, the rest are
+converted to a matrix.
+
 *** Images and files in clipboard can be pasted
 
 Org asks the user what must be done when pasting images and files
diff --git a/lisp/ob-calc.el b/lisp/ob-calc.el
index f36df77ff..810ed1735 100644
--- a/lisp/ob-calc.el
+++ b/lisp/ob-calc.el
@@ -64,7 +64,19 @@
 	 (var-names (mapcar #'symbol-name org--var-syms)))
 (mapc
  (lambda (pair)
-   (calc-push-list (list (cdr pair)))
+   (let ((val (cdr pair)))
+ (calc-push-list
+  ;; For a vector, Calc follows the format (vec 1 2 3 ...)  so
+  ;; a matrix becomes (vec (vec 1 2 3) (vec 4 5 6) ...).  See
+  ;; the comments in "Arithmetic routines." section of
+  ;; calc.el.
+  (list (if (listp val)
+(cons 'vec
+  (if (null (cdr val))
+  (car val)
+(mapcar (lambda (x) (if (listp x) (cons 'vec x) x))
+val)))
+  val
(calc-store-into (car pair)))
  vars)
 (mapc
diff --git a/testing/lisp/test-ob-calc.el b/testing/lisp/test-ob-calc.el
new file mode 100644
index 0..6d6ca104d
--- /dev/null
+++ b/testing/lisp/test-ob-calc.el
@@ -0,0 +1,115 @@
+;;; test-ob-calc.el --- tests for ob-calc.el -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024  Visuwesh
+
+;; Author: Visuwesh 
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as publish

[PATCH] Add support for tables in Calc src block :var

2024-03-15 Thread Visuwesh
Attached patch adds support for passing tables as matrices (or vector)
to a Calc source block through the :var parameter.  There might be a
better way to do it than manually construct the data structure expected
by Calc for a matrix but given that it rarely sees changes in this area,
it shouldn't be a bother.
I also added tests for this feature, and other simple tests to ensure
everything works.  I checked that all the tests passed on my side.

>From 5dd444a3dd688b366e1151739f6a8e8088bb0623 Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Sat, 16 Mar 2024 09:10:53 +0530
Subject: [PATCH] ob-calc: Support passing tables as matrices with :var

A table with MxN dimensions is converted to a MxN matrix when given in
:var to a Calc source block.  A table with a single row is converted
to a vector (i.e., row vector).

* lisp/ob-calc.el (org-babel-execute-src-block:calc): Construct the
right data structure to pass tables as matrices to Calc.
* testing/examples/ob-calc-test.org:
* testing/lisp/test-ob-calc.el: Add tests for ob-calc, and this new
feature.
---
 lisp/ob-calc.el   | 10 +++-
 testing/examples/ob-calc-test.org | 57 ++
 testing/lisp/test-ob-calc.el  | 80 +++
 3 files changed, 146 insertions(+), 1 deletion(-)
 create mode 100644 testing/examples/ob-calc-test.org
 create mode 100644 testing/lisp/test-ob-calc.el

diff --git a/lisp/ob-calc.el b/lisp/ob-calc.el
index f36df77ff..c8bbcd16b 100644
--- a/lisp/ob-calc.el
+++ b/lisp/ob-calc.el
@@ -64,7 +64,15 @@
 	 (var-names (mapcar #'symbol-name org--var-syms)))
 (mapc
  (lambda (pair)
-   (calc-push-list (list (cdr pair)))
+   (let ((val (cdr pair)))
+ (calc-push-list
+  (list (if (listp val)
+(cons 'vec
+  (if (null (cdr val))
+  (car val)
+(mapcar (lambda (x) (if (listp x) (cons 'vec x) x))
+val)))
+  val
(calc-store-into (car pair)))
  vars)
 (mapc
diff --git a/testing/examples/ob-calc-test.org b/testing/examples/ob-calc-test.org
new file mode 100644
index 0..6df44c6a4
--- /dev/null
+++ b/testing/examples/ob-calc-test.org
@@ -0,0 +1,57 @@
+#+TITLE: Tests for ob-calc
+#+OPTIONS: ^:nil
+
+* Simple
+:PROPERTIES:
+:ID:   40e4cd26-fe15-45c0-938b-111e021a5a99
+:END:
+
+#+BEGIN_SRC calc :results silent
+	1 * 2
+#+END_SRC
+
+#+BEGIN_SRC calc :results silent
+	12 + 16 - 1
+#+END_SRC
+
+#+BEGIN_SRC calc :results silent
+	inv(a)
+#+END_SRC
+
+* Tables
+:PROPERTIES:
+:ID:   138938e1-f0ba-4c2b-babe-5d20f2b83557
+:END:
+
+#+NAME: ob-calc-table-1
+| 1 |  2 |  3 |
+| 5 |  6 |  7 |
+| 9 | 14 | 11 |
+
+#+NAME: ob-calc-table-2
+| 1 | 2 | 3 | 4 | 5 |
+
+#+NAME: ob-calc-table-3
+| 1 |
+| 2 |
+| 3 |
+
+#+BEGIN_SRC calc :results silent :var a=ob-calc-table-1
+	inv(a)
+#+END_SRC
+
+#+BEGIN_SRC calc :results silent :var a=ob-calc-table-2
+	a*2 - 2
+#+END_SRC
+
+#+BEGIN_SRC calc :results silent :var a=ob-calc-table-2
+	vmean(a)
+#+END_SRC
+
+#+BEGIN_SRC calc :results silent :var a=ob-calc-table-3
+	a
+#+END_SRC
+
+#+BEGIN_SRC calc :results silent :var a=ob-calc-table-2
+	a
+#+END_SRC
diff --git a/testing/lisp/test-ob-calc.el b/testing/lisp/test-ob-calc.el
new file mode 100644
index 0..443ccd64b
--- /dev/null
+++ b/testing/lisp/test-ob-calc.el
@@ -0,0 +1,80 @@
+;;; test-ob-calc.el --- tests for ob-calc.el -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024  Visuwesh
+
+;; Author: Visuwesh 
+
+;; This program 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.
+
+;; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+(require 'ob-calc)
+
+(unless (featurep 'ob-calc)
+  (signal 'missing-test-dependency "Support for Calc code blocks"))
+
+(ert-deftest ob-calc/simple-program-mult ()
+  "Test of simple multiplication."
+  (org-test-at-id "40e4cd26-fe15-45c0-938b-111e021a5a99"
+(org-babel-next-src-block)
+(should (equal "2" (org-babel-execute-src-block)
+
+(ert-deftest ob-calc/simple-program-arith ()
+  "Test of simple arithmetic."
+  (org-test-at-id "40e4cd26-fe15-45c0-938b-111e021a5a99"
+(org-babel-next-src-block 2)
+(should (equal "27" (org-babel-execute-src-block)
+
+(ert-deftest ob-calc/simple-program-symbolic ()
+  "Test of simple symbolic algebra.

[BUG] ox-odt messes with auto-mode-alist [9.7-pre (release_9.6.11-1090-g76468c.dirty @ /home/viz/lib/emacs/straight/build/org/)]

2024-02-16 Thread Visuwesh


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


ox-odt.el contains the following lines at the end of file:

;;; Library Initializations

(dolist (desc org-odt-file-extensions)
  ;; Let Emacs open all OpenDocument files in archive mode.
  (add-to-list 'auto-mode-alist
   (cons (concat  "\\." (car desc) "\\'") 'archive-mode)))

Is there a reason why this is done?  This breaks the expected result of
opening .odt and friends using doc-view-mode, and causes unnecessary
confusion (it is not particularly easy to find too since grepping
through Emacs for "\\.odt" fails).

Emacs  : GNU Emacs 30.0.50 (build 42, x86_64-pc-linux-gnu, X toolkit, cairo 
version 1.18.0, Xaw scroll bars)
 of 2024-01-31
Package: Org mode version 9.7-pre (release_9.6.11-1090-g76468c.dirty @ 
/home/viz/lib/emacs/straight/build/org/)



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

2023-12-05 Thread Visuwesh
[ஞாயிறு நவம்பர் 05, 2023] Ihor Radchenko wrote:

> Po Lu  writes:
>
>> I have now installed an interface to this end into Emacs 30.  The
>> pertinent documentation is under the ``Drag and Drop'' node in the Lisp
>> reference manual.
>
> Thanks!
>
> [...]
>
> Visuwesh, do you want to update your patch accordingly?

I have now adjusted the patch to insert a space between links when the
Emacs version in <30, and when more than one file is dropped.

>From 93db10f9f0c618be5512fbd67cd7b7676d6b1b0c 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-method, org-yank-image-file-name-function)
(org-yank-dnd-method, org-yank-dnd-default-attach-method): New
defcustoms.
(org--image-yank-media-handler, org--copied-files-yank-media-handler)
(org--dnd-rmc, org--dnd-multi-local-file-handler)
(org--dnd-local-file-handler, org--dnd-attach-file, org--dnd-xds-method)
(org--dnd-xds-function): Add yank-media and DND handlers.

* doc/org-manual.org: (Drag and Drop & ~yank-media~): Describe the new
feature in the manual.

* etc/ORG-NEWS: Advertise the new features.
---
 doc/org-manual.org |  45 
 etc/ORG-NEWS   |  24 +
 lisp/org.el| 248 -
 3 files changed, 316 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 3e9d42f55..7b14eb937 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -21095,6 +21095,51 @@ most recent since the mobile application searches files that were last
 pulled.  To get an updated agenda view with changes since the last
 pull, pull again.
 
+** Drag and Drop & ~yank-media~
+:PROPERTIES:
+:DESCRIPTION: Dropping and pasting files and images
+:END:
+
+#+cindex: dropping files
+#+cindex: dragging files
+#+cindex: drag and drop
+#+cindex: dnd
+#+vindex: org-yank-dnd-method
+Org mode supports drag and drop (DnD) of files.  By default, Org asks
+the user what must be done with the dropped file: attach it, insert
+=file:= link, or open the file.  Customize ~org-yank-dnd-method~ to
+set the default DnD action.
+
+When DnD method is "attach", Org mode first consults DnD metadata to
+decide the attach method.  For example, when file/files are dragged
+from a file manager, Org may attach by copying or by moving.
+
+#+vindex: org-yank-dnd-default-attach-method
+If Org cannot figure out which attachment method to use from the
+metadata, it defaults to ~org-yank-dnd-default-attach-method~ [fn::By
+default, ~org-yank-dnd-default-attach-method~ is set to nil -- use the same
+value as ~org-attach-method~ (~cp~ by default).]
+
+#+cindex: pasting files, images from clipboard
+Starting from Emacs 29, Org mode supports ~yank-media~ command to yank
+images from the clipboard and files from a file manager.
+
+#+vindex: org-yank-image-save-method
+When yanking images from clipboard, Org saves the image on disk and
+inserts the image link to Org buffer.  Images are either saved as
+attachments to heading (default) or to a globally defined directory.
+The save location is controlled by ~org-yank-image-save-method~.
+
+#+vindex: org-yank-image-file-name-function
+The yanked images are saved under automatically generated name.  You
+can customize ~org-yank-image-file-name-function~ to make Org query
+the image names or change the naming scheme.
+
+When yanking files copied from a file manager, Org respects the value
+of ~org-yank-dnd-method~.  Image files pasted this way also respect
+the value of ~org-yank-image-save-method~ when the action to perform
+is =attach=.
+
 * Hacking
 :PROPERTIES:
 :DESCRIPTION: How to hack your way around.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 252c5a9f9..7c40ec0fe 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -596,6 +596,30 @@ 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 pasted
+
+Org asks the user what must be done when pasting images and files
+copied to the clipboard from a file manager using the ~yank-media~
+command.  The default action can be set by customizing
+~org-yank-dnd-method~.  The ~yank-media~ command was added in Emacs
+29.
+
+Images can be saved to a separate directory instead of being attached,
+customize ~org-yank-image-save-method~.
+
+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
+
+By default, Org asks the user what to do with the dropped file like
+for pasted files.  The same user option ~org-yank-dnd-metho

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

2023-11-05 Thread Visuwesh
[ஞாயிறு நவம்பர் 05, 2023] Ihor Radchenko wrote:

> Po Lu  writes:
>
>> I have now installed an interface to this end into Emacs 30.  The
>> pertinent documentation is under the ``Drag and Drop'' node in the Lisp
>> reference manual.
> [...]
> Visuwesh, do you want to update your patch accordingly?

Yes, I intend to.  But this might not happen until December since I am
busy with the end of my semester.



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-23 Thread Visuwesh
[திங்கள் அக்டோபர் 23, 2023] Ihor Radchenko wrote:

>>> Also, we might want to add a subsection describing the new customization to
>>> 17 Miscellaneous section of the manual. Otherwise, users might have
>>> difficulties discovering relevant settings to customize dnd and yank
>>> behavior.
>>
>> I have now added these to the manual with a few relevant concept
>> indices.  Please check if they are understandable as I am terrible at
>> writing documentation.  Thanks.
>
> Thanks!
> Upon reading the manual sections I have further comments on the code:
>
> 1. org-yank-image-save-type feels a bit inconsistent. What about
>org-yank-image-save-method? "Type" sounds more like extension (png,
>jpeg, etc)

You're right, I have now changed the name to say method instead.

> 2. org-dnd-method allows either attaching files/images or putting them
>into a dedicated directory. Same for yanked images. But it is not the
>case for yanked files - they are always attached, which is not
>consistent. May we also allow dedicated directory for yanked files?
>Or maybe simply merge the org-dnd-method customization for yank and
>dnd together.

Hmm... yes, I now made yank-media also respect the value of
org-dnd-method.  I changed the name of org-dnd-method to
org-yank-dnd-method and similarly for the rest of the common user
options.

Here's the new patch:

>From c7492fc2adb72a45691124929527798bf9482c2b 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-method, org-yank-image-file-name-function)
(org-yank-dnd-method, org-yank-dnd-default-attach-method): New
defcustoms.
(org--image-yank-media-handler, org--copied-files-yank-media-handler)
(org--dnd-rmc, org--dnd-attach-file, org--dnd-local-file-handler)
(org--dnd-xds-method, org--dnd-xds-function): Add yank-media and DND
handlers.

* doc/org-manual.org: (Drag and Drop & ~yank-media~): Describe the new
feature in the manual.

* etc/ORG-NEWS: Advertise the new features.
---
 doc/org-manual.org |  45 +
 etc/ORG-NEWS   |  24 +
 lisp/org.el| 231 -
 3 files changed, 299 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 3e9d42f55..7b14eb937 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -21095,6 +21095,51 @@ most recent since the mobile application searches files that were last
 pulled.  To get an updated agenda view with changes since the last
 pull, pull again.
 
+** Drag and Drop & ~yank-media~
+:PROPERTIES:
+:DESCRIPTION: Dropping and pasting files and images
+:END:
+
+#+cindex: dropping files
+#+cindex: dragging files
+#+cindex: drag and drop
+#+cindex: dnd
+#+vindex: org-yank-dnd-method
+Org mode supports drag and drop (DnD) of files.  By default, Org asks
+the user what must be done with the dropped file: attach it, insert
+=file:= link, or open the file.  Customize ~org-yank-dnd-method~ to
+set the default DnD action.
+
+When DnD method is "attach", Org mode first consults DnD metadata to
+decide the attach method.  For example, when file/files are dragged
+from a file manager, Org may attach by copying or by moving.
+
+#+vindex: org-yank-dnd-default-attach-method
+If Org cannot figure out which attachment method to use from the
+metadata, it defaults to ~org-yank-dnd-default-attach-method~ [fn::By
+default, ~org-yank-dnd-default-attach-method~ is set to nil -- use the same
+value as ~org-attach-method~ (~cp~ by default).]
+
+#+cindex: pasting files, images from clipboard
+Starting from Emacs 29, Org mode supports ~yank-media~ command to yank
+images from the clipboard and files from a file manager.
+
+#+vindex: org-yank-image-save-method
+When yanking images from clipboard, Org saves the image on disk and
+inserts the image link to Org buffer.  Images are either saved as
+attachments to heading (default) or to a globally defined directory.
+The save location is controlled by ~org-yank-image-save-method~.
+
+#+vindex: org-yank-image-file-name-function
+The yanked images are saved under automatically generated name.  You
+can customize ~org-yank-image-file-name-function~ to make Org query
+the image names or change the naming scheme.
+
+When yanking files copied from a file manager, Org respects the value
+of ~org-yank-dnd-method~.  Image files pasted this way also respect
+the value of ~org-yank-image-save-method~ when the action to perform
+is =attach=.
+
 * Hacking
 :PROPERTIES:
 :DESCRIPTION: How to hack your way around.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 252c5a9f9..7c40ec0fe 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -596,6 +596,30 @@ re

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-22 Thread Visuwesh
[திங்கள் அக்டோபர் 09, 2023] Ihor Radchenko wrote:

> Thanks!
>
>> +(defun org--dnd-attach-file (url action)
>> ...
>> +(insert
>> + (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
>> + "\n")
>> +'private))
>
>> +(pcase org--dnd-xds-method
>> +  (`attach (insert (org-link-make-string
>> +(concat "attachment:" (file-name-nondirectory 
>> filename)))
>
>> +  (`file-link (insert (org-link-make-string (concat "file:" filename))
>> +  "\n"))
>
> Is there any particular reason why you insert a newline after the image
> link?

I think this can stay here until Po Lu writes the platform-agnostic code
that you requested further down this thread?

> Also, we might want to add a subsection describing the new customization to
> 17 Miscellaneous section of the manual. Otherwise, users might have
> difficulties discovering relevant settings to customize dnd and yank
> behavior.

I have now added these to the manual with a few relevant concept
indices.  Please check if they are understandable as I am terrible at
writing documentation.  Thanks.

>From e8b142db0d91e305cbefbb2c945fee7c40ed03f3 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, org--dnd-rmc): Add yank-media and DND
handlers.

* doc/org-manual.org: (Drag and Drop & ~yank-media~): Describe the new
feature in the manual.

* etc/ORG-NEWS: Advertise the new features.
---
 doc/org-manual.org |  40 
 etc/ORG-NEWS   |  20 
 lisp/org.el| 243 -
 3 files changed, 298 insertions(+), 5 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 3e9d42f55..dcdaa98fa 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -21095,6 +21095,46 @@ most recent since the mobile application searches files that were last
 pulled.  To get an updated agenda view with changes since the last
 pull, pull again.
 
+** Drag and Drop & ~yank-media~
+:PROPERTIES:
+:DESCRIPTION: Dropping and pasting files and images
+:END:
+
+#+cindex: dropping files
+#+vindex: org-dnd-method
+Org can attach, insert =file:= links, or open files dropped onto an
+Emacs frame.  By default, Org asks the user what must be done with the
+dropped file but this can be changed by customizing the user option
+~org-dnd-method~.  Changing the variable can make Org do any of the
+above mentioned actions without prompting.
+
+#+vindex: org-dnd-default-attach-method
+If Org cannot figure out which attachment method to use automatically,
+it defaults to using the attachment method mentioned in
+~org-dnd-default-attach-method~.  Org uses the attachment method
+mentioned in ~org-attach-method~ by default, so Org using the =cp=
+method to attach the dropped files.
+
+#+cindex: pasting files, images from clipboard
+From Emacs 29, Org can deal with images copied to the clipboard, and
+files copied from a file manager when pasted using the command
+~yank-media~.  Org deals with them differently.
+
+#+vindex: org-yank-image-save-type
+#+vindex: org-yank-image-file-name-function
+For images, Org attaches the image when pasting but this can be
+changed by customizing ~org-yank-image-save-type~ to save them under
+another directory instead.  The name given to these images are
+autogenerated by default but you can customize what name should be
+given to the pasted image by customizing
+~org-yank-image-file-name-function~.  This function takes no argument
+and should return the filename without extension to use as the image's
+filename.
+
+For files copied from a file manager, Org attaches them to the current
+heading using the =mv= or the =cp= method if the files were cut or
+copied in the file manager respectively.
+
 * Hacking
 :PROPERTIES:
 :DESCRIPTION: How to hack your way around.
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 obje

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-20 Thread Visuwesh
[வெள்ளி அக்டோபர் 20, 2023] Ihor Radchenko wrote:

> Po Lu  writes:
>
>>> Because nobody added you manually to the CC in this branch of the
>>> discussion. You would only be automatically in the CC in the replies to
>>> your message (87bkdccihf@yahoo.com), but not the earlier branches.
>>
>> The follow-up I mentioned lists 87bkdccihf@yahoo.com within
>> In-Reply-To.
>
> I see. I use wide reply by default, personally. I did not drop you or
> anyone from CC in this thread on purpose.

I also use wide-reply but the problem was that I neglected to include Po
Lu in the CCs when I replied to a message in another sub-thread that
referred to Po Lu's message.  So the issue raised by Po Lu was addressed
but he was effectively dropped from the discussion due to my negligence.

>>> Do you mean something like a standardized entry in `dnd-protocol-alist'
>>> that is independent on OS? Instead of (REGEXP . FUNCTION),
>>> (SYMBOL . FUNCTION) with SYMBOL = 'file-list or so.
>>
>> I'm sorry, but I don't understand what you're proposing.  Would you
>> please couch it differently?
>
> Instead of passing dnd data as is from the OS, Emacs can convert it into
> a standardized format, independent of the OS. Then,
> `dnd-protocol-alist' can allow handlers for such standardized dnd type.
>
> In our scenario, the dnd data will be dropped file list. Emacs should
> internally detect such file lists for GNU/Linux / Windows / other
> platforms with dnd support and then convert them into the same format.
> Then, dnd users can add (file-list . FUNCTION) into `dnd-protocol-alist'
> and the FUNCTION will be passed with the converted data that will always
> be the same for all the OSes.
>
> Does it make sense?

BTW, I would also like to have something like dnd-protocol-alist but for
dropped _text_ instead.  Currently, every dropped text is handled by
dnd-insert-text but I would like to have a handler so that e.g., I can
add the relevant bibtex entry for the DOI _text_ (10.BLAH/BLAH no fancy
link) onto an Emacs window visiting a bibtex file.  I currently do this
via an advice but it would be nice to have something less hacky.



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-19 Thread Visuwesh
[திங்கள் அக்டோபர் 09, 2023] Visuwesh wrote:

> [திங்கள் அக்டோபர் 09, 2023] Ihor Radchenko wrote:
>
>> Thanks!
>>
>>> +(defun org--dnd-attach-file (url action)
>>> ...
>>> +(insert
>>> + (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
>>> + "\n")
>>> +'private))
>>
>>> +(pcase org--dnd-xds-method
>>> +  (`attach (insert (org-link-make-string
>>> +(concat "attachment:" (file-name-nondirectory 
>>> filename)))
>>
>>> +  (`file-link (insert (org-link-make-string (concat "file:" filename))
>>> +  "\n"))
>>
>> Is there any particular reason why you insert a newline after the image
>> link?
>
> It is for when you drop multiple files onto a frame.  AFAIU/AFAICT
> there's no way to know beforehand if multiple files will be dropped or
> not.  I will look into it in bit more detail in the coming days and drop
> the newline if only one file is dropped.

OK, seems like the actual handling is done by x-dnd-handle-uri-list
where the URI list is split and each URI is handled separately.  We can
override this function by our own by changing the entry in
x-dnd-types-alist but we need to do the same for pgtk-dnd-types-alist
and from what I can tell there are no such facilities for MS Windows and
NS?  I think we need to accept that we will have sub-optimal interface
for multi file drops.  WDYT?

Also, can I know what you think about using a popup-menu instead of a
dialog box for prompting as Liu Hui suggests in
https://yhetil.org/orgmode/caoqtw-mas6b2uh9z52ejn7ebwni+suhq9dwe0fky_rzvhox...@mail.gmail.com
?  If you're okay with it, I will write a function to use rmc or
popup-menu for prompting as per what use-dialog-box-p returns.



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-11 Thread Visuwesh
[புதன் அக்டோபர் 11, 2023] Liu Hui wrote:

> Hi,
>
> Thanks for your work. I have two minor suggestions about the patch.
>
>> + (`file-link
>> + (let ((filename (dnd-get-local-file-name url)))
>> + (insert (org-link-make-string (concat "file:" filename
>
> I think it is better to abbreviate the file name for file-link, so it
> would be consistent with org-insert-link.

OK, will do.

>> + (caddr (read-multiple-choice
>> + "What to do with dropped file?"
>> + '((?a "attach" attach)
>> + (?o "open" open)
>> + (?f "insert file: link" file-link
>
> The dialog box is shown in the center of frame and I find it a little
> inconvenient compared with a menu popped up just at the mouse
> location. How about using x-popup-menu?

But isn't that for menus?  I don't know how convenient is a menu
compared to a dialog box.  But if the consensus is that a menu should be
popped, then I will adjust the query to use rmc or menu as per
use-dialog-box.



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-09 Thread Visuwesh
[திங்கள் அக்டோபர் 09, 2023] Ihor Radchenko wrote:

> Thanks!
>
>> +(defun org--dnd-attach-file (url action)
>> ...
>> +(insert
>> + (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
>> + "\n")
>> +'private))
>
>> +(pcase org--dnd-xds-method
>> +  (`attach (insert (org-link-make-string
>> +(concat "attachment:" (file-name-nondirectory 
>> filename)))
>
>> +  (`file-link (insert (org-link-make-string (concat "file:" filename))
>> +  "\n"))
>
> Is there any particular reason why you insert a newline after the image
> link?

It is for when you drop multiple files onto a frame.  AFAIU/AFAICT
there's no way to know beforehand if multiple files will be dropped or
not.  I will look into it in bit more detail in the coming days and drop
the newline if only one file is dropped.

> Also, we might want to add a subsection describing the new customization to
> 17 Miscellaneous section of the manual. Otherwise, users might have
> difficulties discovering relevant settings to customize dnd and yank
> behavior.

OK, I will do so.



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,
+;;

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-07 Thread Visuwesh
[சனி அக்டோபர் 07, 2023] Visuwesh wrote:

> [சனி அக்டோபர் 07, 2023] Ihor Radchenko wrote:
>
>> Visuwesh  writes:
>>
>>> Attached patch considers your review and also another defcustom to tell
>>> how to generate the filename which by default autogenerates a filename
>>> based on current time.
>>
>> Thanks!
>> I still disagree about :safe, but I can change it myself to something
>> more restrictive like :safe (lambda (x) (eq x 'attach)))
>
> OK, I will change it on my end then.  I can always override the :safe
> function on my end.
>
>> Also, it looks like we also need to define `x-dnd-direct-save-function',
>> as Po Lu pointed in 
>> https://list.orgmode.org/orgmode/87bkdccihf@yahoo.com/ 
>
> I will get to it, hopefully by Sunday.

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

>From 7bdd892c0cdb248341e3284e9aeee341f073d38d 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  | 234 ++-
 2 files changed, 253 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..cfb314e23 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,235 @@ 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 'x-dnd-direct-save-function)
+(setq-local x-dnd-direct-save-function #'org--dnd-xds-function)))
+
+(defcustom org-yank-image-save-type 'attach
+  "Method to save images yanked from clipboard and dropped to Emacs.
+It can be the symbol `attach' to add it as an attachment, or a
+directory name to copy/cut the image to that directory."
+  :group 'org
+  :package-version '(Org . "9.7")
+  :type '(choice (const :tag "Add it as attachment" att

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-07 Thread Visuwesh
[சனி அக்டோபர் 07, 2023] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> Attached patch considers your review and also another defcustom to tell
>> how to generate the filename which by default autogenerates a filename
>> based on current time.
>
> Thanks!
> I still disagree about :safe, but I can change it myself to something
> more restrictive like :safe (lambda (x) (eq x 'attach)))

OK, I will change it on my end then.  I can always override the :safe
function on my end.

> Also, it looks like we also need to define `x-dnd-direct-save-function',
> as Po Lu pointed in 
> https://list.orgmode.org/orgmode/87bkdccihf@yahoo.com/ 

I will get to it, hopefully by Sunday.

What do you think about adding a defcustom as requested by Liu Hui in
https://yhetil.org/orgmode/caoqtw-p6_w3heepjftkcfey2rpfgjfouhwmseoe2ajnpoi+...@mail.gmail.com/



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-01 Thread Visuwesh
[வெள்ளி செப்டம்பர் 29, 2023] Liu Hui wrote:

> Hi,
>
> 在 2023/9/27 16:29, Visuwesh 写道:
>
>> +*** 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~.
>
>> +(defcustom org-dnd-default-attach-method nil
>> +  "Default attach method to use when DND action is unspecified.
>> +This attach method is used when the DND action is `private'.
>> +This is also used when `org-yank-image-save-type' is nil.
>> +When nil, use `org-attach-method'."
>
> I think the dnd feature should not be restricted to org-attach. I have
> often used it for opening file and inserting file link. How about
> supporting them and adding a new variable, such as
> org-dnd-default-method?

Thanks for your feedback.  Do you think asking during the time of drop
would be a viable option too?  I'm thinking of adding the defcustom
org-dnd-default-method with options such as

. attach -- as implemented here
. open -- open file
. file-link -- insert file links
. ask -- ask what to do after drop

I think the `ask' option would be nice to have too.  Perhaps, even as
the default?

>> +   ('ask (caddr (org-mks
>> + '(("c" "Copy" cp)
>> +   ("m" "Move" mv)
>> +   ("l" "Hard link" ln)
>> +   ("s" "Symbolic link" lns))
>> + "How to attach?"
>> + "Attach using method")))
>
> It is better to pop up a menu that allows users to proceed with the
> mouse, e.g. that in `dired-dnd-do-ask-action'. Options like
> 'open'/'file link' could be added too.

Thanks, I will go back to using rmc then.  It shows a nice dialog box
when you use the mouse.

> Thanks for your work.



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

2023-09-27 Thread Visuwesh
[செவ்வாய் செப்டம்பர் 26, 2023] Max Nikulin wrote:

> On 25/09/2023 20:14, Visuwesh wrote:
>> +  (setq-local dnd-protocol-alist
>> +  (cons '("^file:///" . org--dnd-local-file-handler)
>> +dnd-protocol-alist))
>
> Does it mean that `org--dnd-local-file-handler' is unconditionally
> called for Org buffers? Current action is to open text files in the
> widow under cursor and it is what users may expect. They may be
> surprised if the file is attached instead.

The common request I see when a file is dropped is to associate it
somehow with the org-mode buffer.  org-attach is the most natural way to
do it.  If the users like the old behaviour, they can remove the entry
from the alist.



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

2023-09-27 Thread Visuwesh
[செவ்வாய் செப்டம்பர் 26, 2023] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>>> Please, use `make-temp-file' to create files in the temporary
>>> directory that may be world writable. Predictable file names there are
>>> undesired from security point of view.
>>
>> What harm does it cause?
>
> /tmp directory can be written by any program and the file, while kept
> there, might be modified by malicious code.
>
> Not that I know a concrete example what harm can be done in this
> particular case, but it is generally a good practice to make file names
> in /tmp random.

I don't see a way in org-attach-attach's mv method to change the
basename of the file post attachment so we have to live with this harm.

>>> I am in doubts if the following code is more suitable for org.el or
>>> for org-attach.el
>>
>> I have the same doubts.
>
> The patch implements dnd and media handlers, which constitute Org mode
> integration with the rest of Emacs. So, they are a part of major mode
> definition. If we want to keep things clean, we may create org-dnd.el
> and org-yank-media.el and put the relevant functions there, only leaving
> the major mode setup in org.el

I think it would be better to keep the registration part in org-mode's
definition in that case since if a user wants to override this
functionality, they can easily do so in org-mode-hook.

> I do not think that org-attach is the right place for this new
> functionality.
>
>>> Could it be extended to any mime type? If so I would avoid "image" in
>>> its name. `org-yank-media-save-dir'?
>>
>> It should be easy enough to do it but do we want to go there?
>
> Isn't the patch handling non-images as well?
> AFAIU, the only case when images are considered separately is when image
> data is in clipboard.

The patch handles non-images in the sense that they are simply attached
using cp/mv method when they are copy/cut to the clipboard from a file
manager.

But if your clipboard data contains video/mpeg for example, then the
patch does nothing.  yank-media would complain about no registered
handlers for video/mpeg.

BTW, before I forget again for the Nth time: there's an issue with how
yank-media works so cut files will not be handled properly unless
bug#65892 gets its clearance.  I hope the description in the linked bug
is clear enough.

>>>> +  "Method to save images yanked from clipboard and dropped to Emacs.
>>>> +It can be the symbol `attach' to add it as an attachment, or a
>>>> +directory name to copy/cut the image to that directory."
>>>> +  :group 'org
>>>> +  :package-version '(Org . "9.7")
>>>> +  :type '(choice (const :tag "Add it as attachment" attach)
>>>> + (directory :tag "Save it in directory"))
>>>> +  :safe (lambda (x) (or (stringp x) (eq x 'attach
>>>
>>> Unsure if every directory may be considered as safe (e.g. ~/.ssh/)
>>
>> Is there a reliable way to know which directory is "safe"?  If not, then
>> let the users shoot themselves in the foot.
>
> We can just say :safe nil (omit the keyword). Then, users will be
> prompted and can decide which directories are truly safe for them.

That would be quite annoying IMO.  I say we let the user shoot
themselves in the foot.

>>>> +(declare-function org-attach-attach "org-attach" (file  
>>>> visit-dir method))
>>>> +
>>>> +(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-media-image-save-type'.  The name for the
>>>> +image is prompted and the extension is automatically added to the
>>>> +end."
>>>> +  (let* ((ext (symbol-name (mailcap-mime-type-to-extension mimetype)))
>>>> + (iname (read-string "Insert filename for image: "))
>>>
>>> Unless 'attach is used, `read-file-name' would allow saving to
>>> arbitrary directory with path completion.
>>
>> Sorry, I don't understand what you mean here.  I am not really familiar
>> with attachment facilities of org-mode.
>
> Imagine that user enters something like
> "/tmp/non-existing-directory/image-file" as an answer to
> "Insert filename for image: " prompt.

How about the following prompt instead?

Basename for image file without extension:

Attached patch has several of the reviews considered.

>From a11658f82ce71850b52b853a4b44055b8f917486 Mon Sep 17 00:00:00 2001
From: Visuwesh 
Date: Fri, 22 Sep 2023 20:11:41 +0530
Subject: [PATCH] Add 

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

2023-09-25 Thread Visuwesh
[ Please keep me in the CC as I don't follow the list.  ]

[ஞாயிறு செப்டம்பர் 24, 2023] Max Nikulin wrote:

> On 23/09/2023 17:28, Ihor Radchenko wrote:
>> Visuwesh writes:
>> 
>>> +  (let* ((ext (symbol-name (mailcap-mime-type-to-extension mimetype)))
>>> + (iname (read-string "Insert filename for image: "))
>> It would be nice if we auto-generate the file name here by
>> default. It
>> is what I would expect from yanking an image at least.
>
> Certainly it would be great to provide some default value allowing
> user to override it. However it may be not so trivial. Clipboard
> content may be just copy region from some graphics editor or a
> screenshot tool, so not associated with a file yet. In X11 xprop may
> be used to get clipboard owner application and its title. Wayland may
> be less permissive.
>
> I have tried to copy an image in Firefox. There is a chance to find
> file name (it may be image.php?id=1324 though) in text/html clipboard
> content, but it requires parsing of HTML
>
> xclip -selection clipboard -o -t text/html

I would rather not go down this rabbit hole since there is no way to
cover all the possible cases.

[ஞாயிறு செப்டம்பர் 24, 2023] Max Nikulin wrote:

> On 22/09/2023 21:52, Visuwesh wrote:
>> Attached patch adds yank-media and DND handler to attach files in the
>> clipboard and dropped onto an Emacs frame respectively.
>
> Please, use `make-temp-file' to create files in the temporary
> directory that may be world writable. Predictable file names there are
> undesired from security point of view.

What harm does it cause?

> Other notes are no more than opinion. I may easily miss something and
> verbose reply may be wasting of time. Do not hesitate to ask more
> details if you do not agree.
>
> At first, I expected more common with the following project
> https://github.com/abo-abo/org-download/
> however even the approach to fetch images from clipboard is different.

I have never used that package, this is what I wrote in a discussion
with Ihor in the Matrix room which we iteratively improved.  It was
mostly written with my workflow in mind.  Without knowledge of how
others work, I cannot improve the implementation.  I also don't
understand what the linked package from the Commentary section (which is
why I never used it).

>> +++ b/lisp/org.el
>
> I am in doubts if the following code is more suitable for org.el or
> for org-attach.el

I have the same doubts.

>> @@ -20254,6 +20257,146 @@ 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))
>> +  (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))
>> +
>> +(defcustom org-media-image-save-type 'attach
>
> Could it be extended to any mime type? If so I would avoid "image" in
> its name. `org-yank-media-save-dir'?

It should be easy enough to do it but do we want to go there?

>> +  "Method to save images yanked from clipboard and dropped to Emacs.
>> +It can be the symbol `attach' to add it as an attachment, or a
>> +directory name to copy/cut the image to that directory."
>> +  :group 'org
>> +  :package-version '(Org . "9.7")
>> +  :type '(choice (const :tag "Add it as attachment" attach)
>> + (directory :tag "Save it in directory"))
>> +  :safe (lambda (x) (or (stringp x) (eq x 'attach
>
> Unsure if every directory may be considered as safe (e.g. ~/.ssh/)

Is there a reliable way to know which directory is "safe"?  If not, then
let the users shoot themselves in the foot.

>> +
>> +(declare-function org-attach-attach "org-attach" (file  visit-dir 
>> method))
>> +
>> +(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-media-image-save-type'.  The name for the
>> +image is prompted and the extension is automatically added to the
>> +end.&qu

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

2023-09-25 Thread Visuwesh
[சனி செப்டம்பர் 23, 2023] Visuwesh wrote:

>>> +(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-media-image-save-type'.  The name for the
>>> +image is prompted and the extension is automatically added to the
>>> +end."
>>> +  (let* ((ext (symbol-name (mailcap-mime-type-to-extension mimetype)))
>>> + (iname (read-string "Insert filename for image: "))
>>
>> It would be nice if we auto-generate the file name here by default. It
>> is what I would expect from yanking an image at least.
>
> Hmm, I think I prefer having a descriptive name for the file.  It would
> aid in searching for the attachment later (in the org document, and
> using find & friends).  We can add a user option but how should the name
> be auto-generated? Timestamp?  I have no ideas in this regard.

Attached patch considers your review and also another defcustom to tell
how to generate the filename which by default autogenerates a filename
based on current time.

>From c9f149cde047a60b6c2a256d96616864f5f66352 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-dnd-default-attach-method)
(org-yank-image-file-name-function): New defcustoms.
(org--image-yank-media-handler, org--copied-files-yank-media-handler)
(org--dnd-local-file-handler): Add yank-media and DND handlers.

* etc/ORG-NEWS: Advertise the new features.
---
 etc/ORG-NEWS |  20 ++
 lisp/org.el  | 169 ++-
 2 files changed, 188 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..d69f9ec70 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,170 @@ 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)))
+
+(defcustom org-yank-image-save-type 'attach
+  "Method to save images yanked from clipboard and dropped to Emacs.
+It can be the symbol `attach' to add it as an attachment, or a
+directory name to copy/cut the image to that directory."
+  :group 'org
+  :package-version '(Org . "9.7")
+  :type 

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

2023-09-23 Thread Visuwesh
[சனி செப்டம்பர் 23, 2023] Ihor Radchenko wrote:

>> +*** 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.
>> +
>> +Images can be saved to a separate directory instead of being attached,
>> +customize ~org-media-image-save-type~.
>
> This requires Emacs 29, which should be documented.

Yes, will do.

>>  ;; Update `customize-package-emacs-version-alist'
>>  (add-to-list 'customize-package-emacs-version-alist
>> @@ -15125,20 +15128,20 @@ INCREMENT-STEP divisor."
>>  (setq hour (mod hour 24))
>>  (setq pos-match-group 1
>>new (format "-%02d:%02d" hour minute)))
>> -   
>> +
>
> These whitespace changes are not relevant.

Sorry, I missed these sneaky changes when I made the commit.

>> +;;; 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))
>> +  (yank-media-handler "image/.*" #'org--image-yank-media-handler)
>
> This function is not yet available in Emacs <29. Need to protect with 
> `fboundp'.

Of course.

>> +(defcustom org-media-image-save-type 'attach
>
> Maybe org-yank-image-save-type?

That is a better name but still doesn't inform the user that it is
respected by DND too.

>> +(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-media-image-save-type'.  The name for the
>> +image is prompted and the extension is automatically added to the
>> +end."
>> +  (let* ((ext (symbol-name (mailcap-mime-type-to-extension mimetype)))
>> + (iname (read-string "Insert filename for image: "))
>
> It would be nice if we auto-generate the file name here by default. It
> is what I would expect from yanking an image at least.

Hmm, I think I prefer having a descriptive name for the file.  It would
aid in searching for the attachment later (in the org document, and
using find & friends).  We can add a user option but how should the name
be auto-generated? Timestamp?  I have no ideas in this regard.



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

2023-09-22 Thread Visuwesh
[வெள்ளி செப்டம்பர் 22, 2023] Max Nikulin wrote:

> On 22/09/2023 21:52, Visuwesh wrote:
>> Attached patch adds yank-media and DND handler to attach files in the
>> clipboard and dropped onto an Emacs frame respectively.
>
> Thank you for your work in this area.
>
> I am not an active DND user, I am just curious what cases are supported:
>
> - X11

Yes.

> - Wayland

I don't know nor am I willing to setup a test environment for it.

> - Sandboxed applications communicating with desktop environment
>   through XDG desktop portal (flatpack/snap/AppImage or just running
>  in bubblewrap)

Same as above.

> - Emacs running on a remote host (ssh + X11 forwarding)

If the DND links are of the form file://HOST/ then the current DND
handler won't run.  I don't have a way to test it myself so I can't
write a handler for remote files.  I am not sure if we can even reuse
the existing the org-attach code for remote files.

> - Windows

I don't have access to a Windows machine so can't test it unfortunately.

> When a file is dropped into an Org buffer I would consider inserting a
> link or storing it in addition to attachment options.

The current code already inserts a link to the dropped files.



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

2023-09-22 Thread Visuwesh
Attached patch adds yank-media and DND handler to attach files in the
clipboard and dropped onto an Emacs frame respectively.

The yank-media handler for images is well tested, I use it frequently
however, rest of the stuff aren't really tested since I don't use a GUI
file manager.  I tested enough to make sure the logic is right so I
don't know if they are ergonomic enough.  As noted in the comments,
files copied/cut to clipboard doesn't seem to have a solid spec and most
of the code was written with pcmanfm as the file manager, testing with
other file managers are highly welcome.

Better names for the newly added defcustoms are highly welcome since I
don't find them to be clear enough from their name.

The patch compiles cleanly without warnings but I haven't tested _this_
patch yet, I have these functions in my init.el and have tested those.

>From b6f1315cbdc331f2f54e1801b03272915d344cfd 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-media-image-save-type, org-dnd-default-attach-method): New
defcustoms.
(org--image-yank-media-handler, org--copied-files-yank-media-handler)
(org--dnd-local-file-handler): Add yank-media and DND handlers.

* etc/ORG-NEWS: Advertise the new features.
---
 etc/ORG-NEWS |  16 ++
 lisp/org.el  | 153 +--
 2 files changed, 164 insertions(+), 5 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 252c5a9..f193c54 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -596,6 +596,22 @@ 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.
+
+Images can be saved to a separate directory instead of being attached,
+customize ~org-media-image-save-type~.
+
+*** 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-media-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 d0b2355..5c66f04 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
@@ -15125,20 +15128,20 @@ INCREMENT-STEP divisor."
 	(setq hour (mod hour 24))
 	(setq pos-match-group 1
   new (format "-%02d:%02d" hour minute)))
-   
+
((org-pos-in-match-range pos 6) ;; POS on "dmwy" repeater char.
 	(setq pos-match-group 6
   new (car (rassoc (+ nincrements (cdr (assoc (match-string 6 ts-string) idx))) idx
-   
+
((org-pos-in-match-range pos 5) ;; POS on X in "Xd" repeater.
 	(setq pos-match-group 5
   ;; Never drop below X=1.
   new (format "%d" (max 1 (+ nincrements (string-to-number (match-string 5 ts-string)))
-   
+
((org-pos-in-match-range pos 9) ;; POS on "dmwy" repeater in warning interval.
 	(setq pos-match-group 9
   new (car (rassoc (+ nincrements (cdr (assoc (match-string 9 ts-string) idx))) idx
-   
+
((org-pos-in-match-range pos 8) ;; POS on X in "Xd" in warning interval.
 	(setq pos-match-group 8
   ;; Never drop below X=0.
@@ -20254,6 +20257,146 @@ 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))
+  (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

Re: [Pre-PATCH] Overhaul of the LaTeX preview system

2023-08-21 Thread Visuwesh
[திங்கள் ஆகஸ்ட் 21, 2023] Karthik Chikmagalur wrote:

>> I have lualatex installed as part of another texlive package but I am
>> not sure if org uses it however.
>
> If you haven't changed `org-latex-compiler' (globally or in the Org
> buffer using a keyword), it's using pdflatex.

I am indeed using pdflatex.

>>> 3. If no, do you mind sharing this file (or a stripped down version
>>> you're okay sharing that still has these issues) along with the LaTeX
>>> preamble?  That would be `org-latex-preview-preamble' and
>>> `org-latex-packages-alist'.  I would like to reproduce this bug.
>
> Please let us know if you can reproduce the precompilation failure.
> This shouldn't be happening.

Hmm, I tried to reproduce it again but failed to do it.  Perhaps, being
a bit more patient is the key.  Sorry for the false alarm.  I will turn
on precompilation and report if/when I can reproduce the failure.

>> No, AFAICT I don't see the issue with png previews.  
>
> Sizing issues with pdflatex+svg previews should be fixed soon.
>
>> However, all latex previews, \( \) and \[ \], seem to be of the same
>> size now.
>
> Should they not be the same size?

After using the svg previews, I was under the impression that inline
maths environments would be at the same size as the rest of the text
whereas the other environments would be at a slightly higher size.

>>> Previewing unadorned LaTeX macros is officially unsupported but
>>> partially supported in practice.  If you move the cursor over the \ch{}
>>> and call `org-latex-preview' it should be previewed.  From that point it
>>> should behave like a regular LaTeX fragment.  Editing it should cause
>>> the preview to be auto-updated (If you are using
>>> org-latex-preview-auto-mode).
>>
>> Is there no automagic way to do this?  Like changing a regexp variable
>> and hoping it would work till the end of time™.  (:
>
> You can change `org-latex-preview--tentative-math-re' to suit your
> needs.  This variable is used to identify LaTeX fragments when calling
> `org-latex-preview'.  All subsequent checks involve the org-element api,
> but for reasons I can't recall at the moment the initial search is via a
> regexp.

Thanks, that seems to work!

> Karthik



Re: [Pre-PATCH] Overhaul of the LaTeX preview system

2023-08-21 Thread Visuwesh
[திங்கள் ஆகஸ்ட் 21, 2023] Karthik Chikmagalur wrote:

>> It worked well all around except for three things:
>>
>> 1. I had to set org-latex-preview-precompile to nil to produce the
>>preview for ~2000 snippets.  I got errors in process filters such
>>as arg-out-of-range, and Emacs completely blocked itself.  I can
>>confirm that mylatexformat is installed
>
> 1. Are you using xelatex/lualatex?  

I have lualatex installed as part of another texlive package but I am
not sure if org uses it however.

> 2. If yes, precompilation should have turned itself off with a warning.
> 3. If no, do you mind sharing this file (or a stripped down version
> you're okay sharing that still has these issues) along with the LaTeX
> preamble?  That would be `org-latex-preview-preamble' and
> `org-latex-packages-alist'.  I would like to reproduce this bug.
>
> Previewing 2000 snippets is exactly where the new async/speedy system is
> expected to shine compared to the old one.
>
>> 2. Apparently, org-latex-default-packages-alist no longer contain
>>asmsymb and asmmath?  This change pulled the rug under me since
>>it took me quite a while to figure out why some of my formulas
>>were coloured red...
>
> `org-latex-default-packages-alist' was modified to omit amsmath and
> amssymb (among others) in preparation for a conditional export system
> where required packages will be determined automatically from the buffer
> text -- i.e. to avoid exactly the kind of headache you encountered.
> Unfortunately this export system is not part of the patch set yet.

Ah, OK.  I will add them in my config and call it a day.  ;-)

>> 3. The image sizes of the same latex environment (e.g., \[ \]) is
>>different for different formulas.  I can send a screenshot of
>>this if required.
>
> This is a recent regression.  Could you generate png previews by:
>
> 1. (setq org-latex-preview-default-process 'dvipng)
> 2. regenerating previews
>
> and checking if this still happens?  If these look fine, this is a
> dvisvgm issue and we will fix it soon.

No, AFAICT I don't see the issue with png previews.  However, all latex
previews, \( \) and \[ \], seem to be of the same size now.

>>> If you do come across any issues, please let me know either in a reply here 
>>> or
>>> the org-mode matrix room. If you could also run
>>>  and 
>>> share the
>>> diagnostic info, that would be quite helpful.
>>
>> If needed, I can do this after reproducing (1).
>>
>> BTW, would it possible to arrange other latex environments (\ch{} in my
>> case) to be previewed as well?  Currently, I do \(\ch{}\) but omitting
>> \( \) would be nice.
>
> Previewing unadorned LaTeX macros is officially unsupported but
> partially supported in practice.  If you move the cursor over the \ch{}
> and call `org-latex-preview' it should be previewed.  From that point it
> should behave like a regular LaTeX fragment.  Editing it should cause
> the preview to be auto-updated (If you are using
> org-latex-preview-auto-mode).

Is there no automagic way to do this?  Like changing a regexp variable
and hoping it would work till the end of time™.  (:

> Karthik



Re: [Pre-PATCH] Overhaul of the LaTeX preview system

2023-08-21 Thread Visuwesh
[ஞாயிறு மார்ச் 12, 2023] Timothy wrote:

> Hi All,
>
> After months of work, Karthink and I have prepared a rather large patch-set
> completely overhauling the LaTeX preview system. I hope to have a patch set
> shortly, but in the mean time it would be good to get some more people testing
> this.
>
> To test this feature, please check out the `dev' branch of
>  (it’s the default branch). There 
> are
> also some other changes there currently, but I don’t think anything is broken.

I tested commit '6eb77305361a1f6a3f67c3229f837f1c4e95f546' of the dev
branch.

It worked well all around except for three things:

1. I had to set org-latex-preview-precompile to nil to produce the
   preview for ~2000 snippets.  I got errors in process filters such
   as arg-out-of-range, and Emacs completely blocked itself.  I can
   confirm that mylatexformat is installed

   % dpkg-query -S mylatexformat
   texlive-latex-extra: 
/usr/share/texlive/texmf-dist/tex/latex/mylatexformat
   texlive-latex-extra: 
/usr/share/texlive/texmf-dist/tex/latex/mylatexformat/mylatexformat.ltx

2. Apparently, org-latex-default-packages-alist no longer contain
   asmsymb and asmmath?  This change pulled the rug under me since
   it took me quite a while to figure out why some of my formulas
   were coloured red...

3. The image sizes of the same latex environment (e.g., \[ \]) is
   different for different formulas.  I can send a screenshot of
   this if required.

Except for these hiccups, it works without a hitch.  Thank you very much
for your work!

> If you do come across any issues, please let me know either in a reply here or
> the org-mode matrix room. If you could also run
>  and share 
> the
> diagnostic info, that would be quite helpful.

If needed, I can do this after reproducing (1).

BTW, would it possible to arrange other latex environments (\ch{} in my
case) to be previewed as well?  Currently, I do \(\ch{}\) but omitting
\( \) would be nice.



Re: [BUG] org-fold-core--fix-folded-region slows down typing [9.6.6 (release_9.6.6 @ /home/viz/lib/ports/emacs/lisp/org/)]

2023-06-09 Thread Visuwesh
[வெள்ளி ஜூன் 09, 2023] Ihor Radchenko wrote:

> Visuwesh  writes:
>
>> In a largeish buffer, org-fold-core--fix-folded-region significantly
>> slows down typing to a point where I have to wait a few milliseconds to
>> see the characters typed.  With emacs -Q, the slow down isn't as bad as
>> with my full configuration but it is still noticeable.  Setting
>> `org-fold-core--ignore-modifications' to t makes the lag go away.
>
> Well. This can happen when you have a huge number of text properties in
> your buffer. It is caused by details of how Emacs stores and searches
> text properties.
>
> You can try to set `org-fold-core-style' to overlays. Or you can try to
> disable flyspell. Or you can try to disable org-num that adds up to text
> properties.

What kind of disasters will I invite if I permanently set
`org-fold-core--ignore-modifications' to t?

> Canceled.
> Not much can be done on Org side.



[BUG] org-fold-core--fix-folded-region slows down typing [9.6.6 (release_9.6.6 @ /home/viz/lib/ports/emacs/lisp/org/)]

2023-06-09 Thread Visuwesh
In a largeish buffer, org-fold-core--fix-folded-region significantly
slows down typing to a point where I have to wait a few milliseconds to
see the characters typed.  With emacs -Q, the slow down isn't as bad as
with my full configuration but it is still noticeable.  Setting
`org-fold-core--ignore-modifications' to t makes the lag go away.

The large buffer that I type in has a PROPERTIES drawer for every
heading there is and I have 481 such headings.  There is one heading
with a couple of drawers that are hundred of lines long and might even
have long lines.  I can send this heading if you would like privately.
The buffer has the following STARTUP options set:

#+STARTUP: fold num

I have attached three files:

· org-fold-core-slow-profile: profiler report in the said large
  buffer with my Emacs configuration.
· org-fold-core-fast-profile: profiler report in a fresh new org
  buffer with only two lines, also recorded with my Emacs
  configuration.
· org-fold-core-emacs-Q-still-kinda-slow: profiler report in the
  said large buffer recorded in `emacs -Q'.

If this is not enough info, please tell me how to help.  Thank you.



org-fold-core-slow-profile
Description: Binary data


org-fold-core-fast-profile
Description: Binary data


org-fold-core-emacs-Q-still-kinda-slow
Description: Binary data


Emacs  : GNU Emacs 29.0.91 (build 2, x86_64-pc-linux-gnu, X toolkit, Xaw scroll 
bars)
 of 2023-06-01
Package: Org mode version 9.6.6 (release_9.6.6 @ 
/home/viz/lib/ports/emacs/lisp/org/)

current state:
==
(setq
 org-agenda-prefix-format '((agenda . " %12:c %12t %s") (todo . " %i %-12:c") 
(tags . " %i %-12:c")
(search . " %i %-12:c"))
 org-attach-preferred-new-method 'dir
 org-link-elisp-confirm-function 'yes-or-no-p
 org-directory "/home/viz/doc/org"
 org-bibtex-headline-format-function #[257 "\300%1\236A\207" [:title] 3 
"\n\n(fn ENTRY)"]
 org-pdftools-get-desc-function 'vz/org-pdftools-link-description
 org-agenda-todo-keyword-format "%s"
 org-agenda-scheduled-leaders '("Scheduled " "Sched. %2d ")
 org-startup-folded t
 org-agenda-skip-scheduled-if-done t
 org-agenda-files '("/home/viz/doc/org/calendar.org" 
"/home/viz/doc/org/habits.org"
"/home/viz/doc/uni/schedule.org" 
"/home/viz/doc/uni/epac.org")
 org-capture-templates '(("u" "University Schedule")
 ("ua" "Assignment" entry
  (file+headline "/home/viz/doc/uni/schedule.org" 
"Changes/Quizzes/Assignments")
  #'doct--fill-template :empty-lines-after 1 :prepend t 
:doct
  (:doct-name "Assignment" :keys "a" :headline 
"Changes/Quizzes/Assignments" :tag
   ":assignment:" :stat "DEADLINE: " :inherited-keys 
"ua" :after-finalize
   vz/update-calendar-markers-after-capture :file 
"/home/viz/doc/uni/schedule.org"
   :prepend t :empty-lines-after 1 :template
   "* TODO %?  %{tag}\n%{stat}%(call-interactively 
#'org-time-stamp)" :doct-custom
   (:tag ":assignment:" :stat "DEADLINE: "))
  )
 ("uq" "Quiz" entry
  (file+headline "/home/viz/doc/uni/schedule.org" 
"Changes/Quizzes/Assignments")
  #'doct--fill-template :empty-lines-after 1 :prepend t 
:doct
  (:doct-name "Quiz" :keys "q" :tag ":quiz:" :headline 
"Changes/Quizzes/Assignments" :stat
   "SCHEDULED: " :inherited-keys "uq" :after-finalize
   vz/update-calendar-markers-after-capture :file 
"/home/viz/doc/uni/schedule.org"
   :prepend t :empty-lines-after 1 :template
   "* TODO %?  %{tag}\n%{stat}%(call-interactively 
#'org-time-stamp)" :doct-custom
   (:tag ":quiz:" :stat "SCHEDULED: "))
  )
 ("uo" "Other" entry
  (file+headline "/home/viz/doc/uni/schedule.org" 
"Changes/Quizzes/Assignments")
  #'doct--fill-template :empty-lines-after 1 :prepend t 
:doct
  (:doct-name "Other" :keys "o" :headline 
"Changes/Quizzes/Assignments" :tag "" :stat
   "SCHEDULED: " :inherited-keys "uo" :after-finalize
   vz/update-calendar-markers-after-capture :file 
"/home/viz/doc/uni/schedule.org"
   :prepend t :empty-lines-after 1 :template
   "* TODO %?  %{tag}\n%{stat}%(call-interactively 
#'org-time-stamp)" :doct-custom
   (:tag "" :stat "SCHEDULED: "))
  )
 ("uh" "Homework" entry
  (file+headline "/home/viz/doc/uni/schedule.org" 
"Changes/Quizzes/Assignments")
  

Re: FR: support hard-newlines [9.5.5 (release_9.5.5 @ /home/viz/lib/ports/emacs/lisp/org/)]

2022-09-20 Thread Visuwesh
[செவ்வாய் செப்டம்பர் 20, 2022] Ihor Radchenko wrote:

>>> All in all, I feel that fully respecting `use-hard-newlines' in Org is
>>> not a good idea. We can do it partially (for filling), but I am afraid
>>> that it may create some confusion.
>>
>> I am not sure what you mean by confusion here: those who have
>> `use-hard-newlines' turned on are explicitly asking for it.  If
>> anything, I was confused when I found org-mode did not recognise
>> hard-newlines.
>
> Let me clarify.
>
> Current state of affairs is: Org ignores `use-hard-newlines'
> Proposed: Org sometimes ignores `use-hard-newline' and sometimes not.
>
> I do believe that what you suggest is a good idea (respecting
> `use-hard-newlines' when filling). However, I notice that some people
> may be more confused if we implement this FR compared to the existing
> situation. So, I am asking for feedback from other users instead of
> accepting the FR.

My point is that I don't see how this is confusing when the user who
turns on use-hard-newlines knows all its caveats, but like you say, lets
see what others say.

>> AFAICT, the rest two are comments (though I cannot tell the difference
>> between "comment" and "comment-block").  I replaced the one in paragraph
>> since that was where lack of hard-newlines support bit me.
>
> [...]
>
> I do not see why `use-hard-newline' should affect normal paragraphs but
> not comments.

I phrased my poorly.  I did not look at the calls of
fill-paragraph-as-region simply because the I hadn't tried to use
hard-newlines in comments.  I agree that we should support it comments
too.



Re: FR: support hard-newlines [9.5.5 (release_9.5.5 @ /home/viz/lib/ports/emacs/lisp/org/)]

2022-09-20 Thread Visuwesh
[செவ்வாய் செப்டம்பர் 20, 2022] Ihor Radchenko wrote:

>> 1. When you want to end a line with a link and continue text in the
>>next line.  You don't care about the export since it will be
>>taken care of properly.
>> 2. When reflowing text with inline latex in them.  You adjust the
>>line width so that it looks like 80 columns are present in a
>>single line.  With hard-newlines, this becomes a very easy job
>>without with you have to isolate the line of interest into a
>>separate paragraph, then do the manual reflow, rinse and repeat.
>
> This sounds as a reasonable use case. However, the Emacs definition of
> hard newlines also involves re-defining paragraph breaks. I do not think
> that it is a good idea for Org to alter Org paragraph syntax depending
> on `use-hard-newlines' - it will create too much confusion when Org
> documents are opened outside Emacs.

I do not think it is necessary for org to recognise hard-newlines as a
paragraph break either since, after all, the presence of hard-newlines
is ephemeral.

>> 3. When writing a list, you give a short description at the top.
>>Then continue writing down below like this without the need to
>>insert a empty line after the first line.
>
> Note that _not_ having an empty line after the first line can be
> misleading. In Org syntax, absence of line will merge description and
> the text below into a single paragraph. It will, for example, affect
> export.

I do get your point, but sometimes there are situations where merging
does not cause confusion and I would like to have the ability to write
lists like no. 3.  This is more true when you, like me, treat org-mode
as a major-mode which enhances plain text files.  If i was exporting,
then I wouldn't rely on org-mode handling hard-newlines (kind of like
how HTML behaves wrt requiring ).

>> My point is that there are several instances where you need a solution
>> that is less aggressive than \\ and hard-newlines hit that sweet spot
>> perfectly.
>
> All in all, I feel that fully respecting `use-hard-newlines' in Org is
> not a good idea. We can do it partially (for filling), but I am afraid
> that it may create some confusion.

I am not sure what you mean by confusion here: those who have
`use-hard-newlines' turned on are explicitly asking for it.  If
anything, I was confused when I found org-mode did not recognise
hard-newlines.

>> -   (fill-region-as-paragraph c end justify)
>> +   (fill-region c end justify)
>
> There are 3 calls to `fill-region-as-paragraph' inside
> `org-fill-element'. If we decide to support `use-hard-newlines'
> partially, all 3 calls should probably be replaced.

AFAICT, the rest two are comments (though I cannot tell the difference
between "comment" and "comment-block").  I replaced the one in paragraph
since that was where lack of hard-newlines support bit me.



FR: support hard-newlines [9.5.5 (release_9.5.5 @ /home/viz/lib/ports/emacs/lisp/org/)]

2022-09-18 Thread Visuwesh


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


Hard-newlines [1] are an excellent way to inform Emacs to stop refilling
lines.  In a way, this serves a similar purpose to org's \\ but with a
major difference being that hard-newlines are not saved to file.  There
are several cases where this is the desired behaviour:
1. When you want to end a line with a link and continue text in the
   next line.  You don't care about the export since it will be
   taken care of properly.
2. When reflowing text with inline latex in them.  You adjust the
   line width so that it looks like 80 columns are present in a
   single line.  With hard-newlines, this becomes a very easy job
   without with you have to isolate the line of interest into a
   separate paragraph, then do the manual reflow, rinse and repeat.
3. When writing a list, you give a short description at the top.
   Then continue writing down below like this without the need to
   insert a empty line after the first line.

My point is that there are several instances where you need a solution
that is less aggressive than \\ and hard-newlines hit that sweet spot
perfectly.
I currently don't have a git checkout of org-mode handy so cannot
produce a patch wrt master branch but changing
`fill-region-as-paragraph' to `fill-region' does the job, as in

diff --git a/lisp/org/org.el b/lisp/org/org.el
index 6f92cdeab5..d53c8c0243 100644
--- a/lisp/org/org.el
+++ b/lisp/org/org.el
@@ -19580,7 +19580,7 @@ org-fill-element
  (org-element-context
 (push (point) cuts)))
 (dolist (c (delq end cuts))
-  (fill-region-as-paragraph c end justify)
+  (fill-region c end justify)
   (setq end c
 t)))
;; Contents of `comment-block' type elements should be

   
1. See C-h f use-hard-newlines RET

Emacs  : GNU Emacs 29.0.50 (build 12, x86_64-pc-linux-gnu, X toolkit, cairo 
version 1.16.0, Xaw scroll bars)
 of 2022-09-17
Package: Org mode version 9.5.5 (release_9.5.5 @ 
/home/viz/lib/ports/emacs/lisp/org/)



[BUG] org-agenda-remove-restriction-lock does not remove file lock [9.5.2 (release_9.5.2-17-gea6b74 @ /nix/store/iqqk7iqfwmfc6r78xg2knyq7hww2mhs4-emacs-git-20220225.0/share/emacs/29.0.50/lisp/org/)]

2022-03-25 Thread Visuwesh


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


C-u C-c C-x < followed by C-c C-x > does not remove the file restriction
lock.  

`org-agenda-remove-restriction-lock' checks for non-nil value of
`org-agenda-restriction' but `org-agenda-set-restriction-lock' explicitly
sets it to nil when TYPE is 'file.  Setting `org-agenda-restriction' to
a dummy value like 'dummy gets the job done.

Emacs  : GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo 
version 1.16.0, Xaw scroll bars)
Package: Org mode version 9.5.2 (release_9.5.2-17-gea6b74 @ 
/nix/store/iqqk7iqfwmfc6r78xg2knyq7hww2mhs4-emacs-git-20220225.0/share/emacs/29.0.50/lisp/org/)



Re: [BUG] org-insert-link should use DEFAULT in read-string when asking for description

2022-02-27 Thread Visuwesh
[ Please keep me in the CCs since I don't follow the list.  ]

[ஞாயிறு, பிப்ரவரி 27 2022] Max Nikulin wrote:

> On 26/02/2022 21:16, Visuwesh wrote:
>> [சனி, பிப்ரவரி 26 2022] Max Nikulin wrote:
>> 
>>> Are you suggesting replacing
>>>  (read-string "rs-initial: " "Some initial")
>>> by
>>>  (read-string "rs-default: " nil nil "Some default")
>>> ?
>> Yes, exactly.
>
> However you agreed that it would be regression since empty description
> use case would be impossible.
>

No.  It is impossible to do it using read-string, but it is possible to
do it by writing a function that calls read-from-minibuffer (and I gave
an example of a function that does this).

>> I admit that I forgot about this but Emacs can be made to not translate
>> empty string to the default argument if you DTRT when calling
>> `read-from-minibuffer' (and `read-shell-command' does this).  If writing
>> a new function just to get this functionality is too much, then I guess
>
> `read-shell-command' still has INITIAL argument and it is used by
> various callers (vc, grep). In addition, unlike for link description,
> I do not see any point in empty shell command (e.g. in vim :! allows
> to see output of previous shell command). So `read-shell-command' may
> behave quite differently.
>

Two things:

1. I dislike grep's behaviour.  However, I understand why grep
   behaves the way it does.  It makes far more sense to use the
   INITIAL argument in grep, but I don't see the same for
   org-insert-link.

   [ In grep, you rarely ever need to change the initial input.  ]

2. The reason why I cited read-shell-command does not have anything
   to do with the usefulness of empty string (or shell command).  I
   merely wanted to point out that you can have BOTH the DEFAULT
   argument (and no INITIAL), and can make the empty string a valid
   output from the function (i.e., without getting substituted by
   the DEFAULT argument).

I hope (2) makes sense.  I'm struggling to word it.

> Current way to ask for link description has the following properties:
> - Almost no action (just RET) if the user happy with suggested
>   description. Default description is provided with hope that it is
>   the most convenient option.
> - It is possible to erase everything and to get a link with no description.
> - The user is free to replace default description with arbitrary
>   alternative text.
>
> It is unclear for me how to tame `read-from-minibuffer' to get equally
> convenient behavior using DEFAULT argument instead of formally
> deprecated INITIAL one.
>

Please read the docstring of read-from-minibuffer.  You would be better
served by reading it than me replicating it here.  And I gave
read-shell-command as an example so others could study the function.

In essence, you can get the old behaviour (1) but you need to type M-n
beforehand.  Its one more key but it is far better than the current
behaviour since it is consistent with rest of the Emacs ecosystem (see
below also).

>> I can live with the current behaviour, but this inconsistency is an
>> annoyance since I end up with garbled link names, which I only notice
>> _afterwards_.
>
> Sorry, but I have not figured out what particular problem you met.

Inconsistency is the problem.  org-insert-link breaks my muscle memory.
I am not sure if you use the default completion system, but if you do,
org-insert-link sticks out by being intrusive.

With every command I use, when I know that the DEFAULT argument will be
of no use, I simply start typing.  However, with org-insert-link I have
to clear the input _first_ then start typing.  This never happens
elsewhere, even in grep (which you cite as an example)!



Re: [BUG] org-insert-link should use DEFAULT in read-string when asking for description

2022-02-26 Thread Visuwesh
[சனி, பிப்ரவரி 26 2022] Max Nikulin wrote:

> On 25/02/2022 21:19, Visuwesh wrote:
>> Currently, when asking the user for the description of link,
>> `org-insert-link' calls `read-string' with a non-nil INITIAL-INPUT but
>> this argument is discouraged and deprecated; moreover, it is unfriendly.
>> `org-insert-link' should, ideally, use the DEFAULT argument.  If the
>> user decides that the suggested description is okay, they can type M-n.
>
> Due to lack of experience with emacs I can miss something. If so,
> please, correct me.
>
> Are you suggesting replacing
> (read-string "rs-initial: " "Some initial")
> by
> (read-string "rs-default: " nil nil "Some default")
> ?

Yes, exactly.

> Is it possible to override provided default description by empty
> string in the latter variant? Currently it is possible to erase
> description using just backspace or C-S-backspace.
>

I admit that I forgot about this but Emacs can be made to not translate
empty string to the default argument if you DTRT when calling
`read-from-minibuffer' (and `read-shell-command' does this).  If writing
a new function just to get this functionality is too much, then I guess
I can live with the current behaviour, but this inconsistency is an
annoyance since I end up with garbled link names, which I only notice
_afterwards_.

> P.S. Many GUI applications pre-select whole value when some input
> field is focused, so it is possible to overwrite current value by
> typing anything. It may be convenient but is not consistent with emacs
> behavior. Moreover it makes uncertain if visually selected text
> overwrites X PRIMARY selection.

I would rather not go there.  You seem to describe
`delete-selection-mode' which, IMO, is also a nuisance given how
mark+point is not the same as "regular selections" (even with
`transient-mark-mode' turned on).



[BUG] org-insert-link should use DEFAULT in read-string when asking for description

2022-02-25 Thread Visuwesh


Currently, when asking the user for the description of link,
`org-insert-link' calls `read-string' with a non-nil INITIAL-INPUT but
this argument is discouraged and deprecated; moreover, it is unfriendly.

`org-insert-link' should, ideally, use the DEFAULT argument.  If the
user decides that the suggested description is okay, they can type M-n.

Regards

Emacs  : GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo 
version 1.16.0, Xaw scroll bars)
Package: Org mode version 9.5.2 (release_9.5.2-9-g7ba24c @ 
/nix/store/0m0yw7b3zly74ljs3qmkblb780xg03id-emacs-git-20220130.0/share/emacs/29.0.50/lisp/org/)