Re: [FR] Please add environment variable substitution in `org-display-inline-images'

2023-05-31 Thread Pan Xie
I think that depends on whether the linter will verify the existence of 
each file path. Strictly speaking, it should, thus the org-lint also 
need changing. On the other hand, if the tool just verify the grammar of 
the org file itself, then it might be OK without changing. I never use 
the linter before, might give it a try sometime.



But the export functionality definitely need changing, otherwise the 
images won't be shown in exported html (or other format) files, and 
someone will report a bug.


On 6/1/23 08:12, Samuel Wales wrote:

org-lint might need changing too?

On 5/31/23, Pan Xie  wrote:

Fantastic!! Thanks for your help. I can remove my ugly override codes.

BTW, Please keep in mind that the org export codes also need to
substitute the environment variables. My proposal only works for the org
file itself, When exports the org file to html, the image file path will
still include the environment variable, which is of course not correct.

On 5/31/23 16:24, Ihor Radchenko wrote:

Pan Xie  writes:


I recently found that the environment variable substitution does not
apply to inline image paths. Supposing I use a path
“/home/pxie/$Gallery/” to store all my image files, “$Gallery”
should be substituted with its corresponding value. The file link DOES
substitute the environment variables, but inline image paths not. So I
think it is a reasonable demand for the consistency.

Agree.
Done, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=3123caa8e









Re: [FR] Please add environment variable substitution in `org-display-inline-images'

2023-05-31 Thread Samuel Wales
org-lint might need changing too?

On 5/31/23, Pan Xie  wrote:
> Fantastic!! Thanks for your help. I can remove my ugly override codes.
>
> BTW, Please keep in mind that the org export codes also need to
> substitute the environment variables. My proposal only works for the org
> file itself, When exports the org file to html, the image file path will
> still include the environment variable, which is of course not correct.
>
> On 5/31/23 16:24, Ihor Radchenko wrote:
>> Pan Xie  writes:
>>
>>> I recently found that the environment variable substitution does not
>>> apply to inline image paths. Supposing I use a path
>>> “/home/pxie/$Gallery/” to store all my image files, “$Gallery”
>>> should be substituted with its corresponding value. The file link DOES
>>> substitute the environment variables, but inline image paths not. So I
>>> think it is a reasonable demand for the consistency.
>> Agree.
>> Done, on main.
>> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=3123caa8e
>>
>
>


-- 
The Kafka Pandemic

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



Re: [PATCH] lisp/org-id.el: Add new relative timestamp feature for `ts' `org-id-method'

2023-05-31 Thread Kierin Bell
Ihor Radchenko  writes:

> Kierin Bell  writes:
>
>> 3. I have implemented a check to verify that `org-id-ts-relative-function' is
>> only called in Org mode buffers. But since I am uncertain about all of
>> the possible contexts in which `org-id-new' can be called, I am not
>> completely sure if it is adequate:
>>
>> --8<---cut here---start->8---
>> (defun org-id-ts-relative-get-effective ()
>>   "Get an effective time using `org-id-ts-relative-function'.
>>
>> Ensure that `org-id-ts-relative-function' is only called in the
>> proper environment (an Org buffer), and return nil otherwise."
>>   (when (and (derived-mode-p 'org-mode)
>>  (functionp org-id-ts-relative-function))
>> (funcall org-id-ts-relative-function)))
>> --8<---cut here---end--->8---
>
> I do not like this approach too much.
> I think that more reliable approach would be adding a new optional
> argument CONTEXT to `org-id-new'. Then, `org-id-get' can pass the
> context (buffer marker) letting `org-id-new' know the aimed location of
> the newly created ID.

I think that your suggestion is a better idea.

It might also be a good idea to refactor `org-id-new' so that the
different ID methods are more composable.

One nice way to do this would be to create a new option that supersedes
(but does not override) `org-id-method' and takes a list of functions
that are tried in order, so that:

(setopt org-id-method 'ts
org-id-ts-relative t
org-id-ts-relative-function
#'org-id-ts-relative-from-keyword-or-property)

... would be equivalent to:

(setopt org-id-function-list '(org-id-relative-ts-keyword
   org-id-relative-ts-property
   org-id-ts))

It would then be easy, for example, to instead set the variable so that
a timestamp value is searched for in properties first *and then* in
keywords if that fails.

Or, perhaps someone will want to implement an `org-id-semantic-ts' ID
method that takes a file with the keywords:

#+title:  Title of File
#+date:   [2023-06-01 Thu 00:00]

...And creates an ID that looks like:

20230601T00--title-of-file+0.00

Users could abuse my new `org-id-ts-effective-format' option to achieve
this, or we could add an `org-id-ts-infix' option, and so on. But it
would be better to have ID methods that are each narrowly focused in
purpose, with an easy extension mechanism so that we won't have any
qualms about the focus being too narrow.

I do understand that ID methods may be intentionally difficult to
extend, because IDs should be stable and consistent. But I don't think
that extensibility, human-friendliness and consistency are necessarily
mutually exclusive.

So, what do you think about the `org-id-function-list' option?

Either way, I'll work on refactoring the patch to make things as modular
as possible.

-- 
Kierin Bell
GPG Key: FCF2 5F08 EA4F 2E3D C7C3  0D41 D14A 8CD3 2D97 0B36



[PATCH] float format specifier in ob-C.el

2023-05-31 Thread Leo Butler
In ob-C.el, line 339 has the format specifier

(`floatp '("double" "%f"))

to print literal floats. However, that format specifier rounds, which
can result in errors. I think the correct approach is to print the
float without rounding or padding or trying to guess at the desired
accuracy (and let the compiler do whatever is needed):

   (`floatp '("double" "%s"))

Attached is a patch with a test that illustrates the problem (it fails
on HEAD but passes with the patch).

Leo



diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 3a6e99623..6b9898ebb 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -339,7 +339,7 @@ FORMAT can be either a format string or a function which is called with VAL."
 	 (type
 	  (pcase basetype
 	(`integerp '("int" "%d"))
-	(`floatp '("double" "%f"))
+	(`floatp '("double" "%s"))
 	(`stringp
 	 (list
 	  (if (eq org-babel-c-variant 'd) "string" "const char*")
diff --git a/testing/examples/ob-C-test.org b/testing/examples/ob-C-test.org
index c7a96f665..58ace91de 100644
--- a/testing/examples/ob-C-test.org
+++ b/testing/examples/ob-C-test.org
@@ -60,6 +60,12 @@
   return 0;
 #+end_src
 
+#+source: float_var
+#+begin_src cpp :var x=1.123456789012345678 :includes "" :results silent
+double y = 1.123456789012345678;
+std::cout << (x == y);
+#+end_src
+
 * Array
   :PROPERTIES:
   :ID:   2df1ab83-3fa3-462a-a1f3-3aef6044a874
diff --git a/testing/lisp/test-ob-C.el b/testing/lisp/test-ob-C.el
index b6dbed8e3..41b500d5b 100644
--- a/testing/lisp/test-ob-C.el
+++ b/testing/lisp/test-ob-C.el
@@ -95,6 +95,13 @@
 		  (org-babel-next-src-block 10)
 		  (should (= 42 (org-babel-execute-src-block))
 
+(ert-deftest ob-C/float-var ()
+  "Test of a string variable"
+  (if (executable-find org-babel-C++-compiler)
+  (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
+		  (org-babel-next-src-block 11)
+		  (should (= 1 (org-babel-execute-src-block))
+
 (ert-deftest ob-C/table ()
   "Test of a table output"
   (if (executable-find org-babel-C++-compiler)


Re: [FR] Please add environment variable substitution in `org-display-inline-images'

2023-05-31 Thread Pan Xie

Fantastic!! Thanks for your help. I can remove my ugly override codes.

BTW, Please keep in mind that the org export codes also need to 
substitute the environment variables. My proposal only works for the org 
file itself, When exports the org file to html, the image file path will 
still include the environment variable, which is of course not correct.


On 5/31/23 16:24, Ihor Radchenko wrote:

Pan Xie  writes:


I recently found that the environment variable substitution does not
apply to inline image paths. Supposing I use a path
“/home/pxie/$Gallery/” to store all my image files, “$Gallery”
should be substituted with its corresponding value. The file link DOES
substitute the environment variables, but inline image paths not. So I
think it is a reasonable demand for the consistency.

Agree.
Done, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=3123caa8e





Re: Restricting files for caldav sync

2023-05-31 Thread Ihor Radchenko
"Loris Bennett"  writes:

> I have a lisp function for syncing my appointments from 'calendar.org'
> to a Nextcloud instance via Caldav.  The variable org-caldav-inbox is
> set to 'calendar.org' and org-caldav-files is set to 'nil'.
>
> However, when I run the function, all the files which contain IDs are
> considered, five files in total, including a large archive file.  This
> makes the sync take rather a long time.
>
> How do I restrict the sync to just a single file?

AFAIU, your settings should be good enough. You may have better luck
contacting org-caldav dev at https://github.com/dengste/org-caldav/issues

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



Re: adding rules for flyspell

2023-05-31 Thread Ihor Radchenko
John Kitchin  writes:

> I use flyspell, and it looks like org-mode
> sets flyspell-generic-check-word-predicate to be org-mode-flyspell-verify.

Not directly. Rather we do

(put 'org-mode 'flyspell-mode-predicate 'org-mode-flyspell-verify)

Then, flyspell uses this symbol value as the default value for
`flyspell-generic-check-word-predicate'.

> I have a few places I would like to augment this to avoid flyspell overlays
> in different places. In the past I have done this with around advice, which
> was ok for one rule, but less desirable for many rules.
>
> does anyone do anything clever here? I am currently making a list of
> predicate functions, and a generic function that runs each one, but I
> wondered if there was another approach. thanks.

AFAIK, there is no better interface provided by flyspell.
The most reliable approach I may think of is storing the value of
`flyspell-generic-check-word-predicate', and then replacing it with your
function that calls the previous value and then does more checking as
needed.

Looking into the docstring, I feel that flyspell could be changed to
accept a hook instead of a single function - the return values will fit
well into `run-hook-with-args-until-success'.

(defvar-local flyspell-generic-check-word-predicate nil
  "Function providing per-mode customization over which words are flyspelled.
Returns t to continue checking, nil otherwise.
Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
property of the major mode name.")

This is something we can request from Emacs devs for future.

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



Re: [RFC] Refactoring org-element API

2023-05-31 Thread Ihor Radchenko
Stefan Nobis  writes:

> One minor nitpick: I would prefer a function like
> ~org-element-property-1~ to be named e.g. ~org-element-property-lazy~
> (or something similar), because the "-1" is just obfuscation to me.

foo-...-1 is actually frequently used in Emacs code for semi-internal
helper functions.

I do not mind alternative name, although I feel that
~org-element-property-lazy~ is not very descriptive.
I'd prefer to see several more ideas about the alternative names, if
possible.

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



Re: [FR] Please add environment variable substitution in `org-display-inline-images'

2023-05-31 Thread Ihor Radchenko
Pan Xie  writes:

> I recently found that the environment variable substitution does not
> apply to inline image paths. Supposing I use a path
> “/home/pxie/$Gallery/” to store all my image files, “$Gallery”
> should be substituted with its corresponding value. The file link DOES
> substitute the environment variables, but inline image paths not. So I
> think it is a reasonable demand for the consistency.

Agree.
Done, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=3123caa8e

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