Re: Using lexical-binding

2021-03-03 Thread Kyle Meyer
Kyle Meyer writes:

> Stefan Monnier writes:
>
>> Since I'm not using it, I can't really test the result in any meaningful
>> way.  Furthermore, just like `calendar.el`, it relies on dynamic scoping
>> and `eval` in all kinds of ways, so it's very difficult to be sure the
>> result is "sufficiently similar" to the old behavior not to break some
>> funky use somewhere out there.
>
> I probably don't use many fancy agenda features, but I do work regularly
> from it.  Running with these changes throughout today, I didn't notice
> any issues.  Within the next few days, I'll try to test some non-default
> settings and more obscure features that I don't use as part of my normal
> workflow, and see if I can find any problems.

I've continued to run with these changes and still haven't noticed any
problems.  I've also tested various features (sticky agendas, block
agendas, option setting from custom commands) and didn't spot anything.

> I'll also push the current changes to scratch/sm/agenda-lexical with the
> hope that others will test and report back.

Has anyone else tried this out?



Re: [PATCH] Reduce code duplication in ob-sql.el and ob-sqlite.el

2021-03-03 Thread Kyle Meyer
Nick Savage writes:

> Hi everyone,
>
> See the attached patch. It is a small change to reduce code duplication 
> between ob-sql.el and ob-sqlite.el by reusing org-babel-sql-expand-vars 
> as suggested by the FIXME in ob-sqlite.el.

Thank you.  Looks good, though I think it'd be nice to keep
org-babel-sqlite-expand-vars around for a bit, marked as obsolete.

> Subject: [PATCH] Reduce code duplication in ob-sqlite.el and ob-sql.el
>
> * lisp/ob-sqlite.el (org-babel-sqlite-expand-vars): removed function
> to replace with ob-sql.el version
> * lisp/ob-sql.el (org-babel-sql-expand-vars): updated to support
> expanding sqlite vars

Please capitalize the first word after ":" and end the entries with a
period.

  https://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html

> -(defun org-babel-sqlite-expand-vars (body vars)
> -  "Expand the variables held in VARS in BODY."
> -  ;; FIXME: Redundancy with org-babel-sql-expand-vars!
> -  (mapc
> -   (lambda (pair)
> - (setq body
> -(replace-regexp-in-string
> - (format "$%s" (car pair))
> - (let ((val (cdr pair)))
> -  (if (listp val)
> -  (let ((data-file (org-babel-temp-file "sqlite-data-")))
> -(with-temp-file data-file
> -  (insert (orgtbl-to-csv val nil)))
> -data-file)
> -(if (stringp val) val (format "%S" val
> - body)))
> -   vars)
> -  body)
> -

How about marking this with (declare (obsolete ...)) and keeping it
around as a wrapper that calls org-babel-sql-expand-vars?  That will
give any third-party code that may have used this for whatever reason
(perhaps unlikely) a chance to update.



Re: [PATCH] Async session eval (2nd attempt)

2021-03-03 Thread Kyle Meyer
Jack Kamm writes:

> I also have an async implementation for ob-R that's ready after this is
> merged :)

It's a bit disappointing that only one babel user has tested this out
and provided feedback, but please feel free to merge this whenever you
think it's ready.

I'm very happy to leave the babel details to you, but here are minor
comments from a quick read-through looking for things that will likely
be changed/cleaned up (either in the Org repo or the Emacs repo) if left
as is.

> Subject: [PATCH] ob-comint.el, ob-python.el: Async session evaluation
[...]
> +;; Async evaluation

For a heading comment, please use at least three semicolons.

  (info "(elisp)Comment Tips")

> +
> +(defvar-local org-babel-comint-async-indicator nil
> +  "Regular expression that `org-babel-comint-async-filter' scans for.
> +It should have 2 parenthesized expressions,
> +e.g. \"org_babel_async_\\(start\\|end\\|file\\)_\\(.*\\)\". The
> +first parenthesized expression determines whether the token is
> +delimiting a result block, or whether the result is in a file. If
> +delimiting a block, the second expression gives a UUID for the
> +location to insert the result. Otherwise, the result is in a tmp
> +file, and the second expression gives the file name.")
> +
> +(defvar-local org-babel-comint-async-buffers nil
> +  "List of org-mode buffers to check for Babel async output results.")

s/org-mode/Org mode/ here and other spots, following
doc/Documentation_Standards.org and tree-wide cleanups like de24694f0
(Turn org-mode into Org or Org mode, 2016-08-23).

Also, you're missing two spaces between some sentences.

> +(defmacro org-babel-comint-async-delete-dangling-and-eval
> +(session-buffer  body)
> +  "Remove dangling text in SESSION-BUFFER and evaluate BODY.
> +This is analogous to `org-babel-comint-with-output', but meant
> +for asynchronous output, and much shorter because inserting the
> +result is delegated to `org-babel-comint-async-filter'."
> +  (declare (indent 1))
> +  `(org-babel-comint-in-buffer ,session-buffer
> + (goto-char (process-mark (get-buffer-process (current-buffer
> + (delete-region (point) (point-max))
> + ,@body))
> +(def-edebug-spec org-babel-comint-async-with-output (sexp body))

Please move this edebug spec to the `declare' form (see 7dd1cfb6c,
2021-02-12).

> diff --git a/testing/lisp/test-ob-python.el b/testing/lisp/test-ob-python.el
> index a2cc7b79c..0267678cd 100644
> --- a/testing/lisp/test-ob-python.el
> +++ b/testing/lisp/test-ob-python.el
> @@ -207,6 +207,67 @@ (ert-deftest test-ob-python/session-value-sleep ()
>  #+end_src"
>   (org-babel-execute-src-block)
>  
> +(ert-deftest test-ob-python/async-simple-session-output ()
> +  (let ((org-babel-temporary-directory "/tmp")

Prefer `temporary-file-directory' to hard coding "/tmp".

Thanks.



Re: [PATCH] Query when exiting with running clock

2021-03-03 Thread Kyle Meyer
Allen Li writes:

> Thanks for your feedback.  I have addressed your comments.  Please see
> the new patches.

Thanks.  Pushed with a few modifications and a commit on top that adds a
NEWS entry.

1:  39422ba4a ! 1:  303e7c28e org-clock: Query when exiting with running clock
@@ Commit message
 * lisp/org-clock.el (org-clock-kill-emacs-query): New function.
 (org-clock-ask-before-exiting): New user option.
 
+[km: added package-version keyword, fixed function name typo]
+
 
  ## Notes (amlog) ##
 Message-Id: 

@@ lisp/org-clock.el: (defcustom org-clock-auto-clockout-timer nil
  
 +(defcustom org-clock-ask-before-exiting t
 +  "If non-nil, ask if the user wants to clock out before exiting Emacs.
-+  This variable only has effect if set with \\[customize]."
++This variable only has effect if set with \\[customize]."
 +  :set (lambda (symbol value)
 + (if value
 + (add-hook 'kill-emacs-query-functions 
#'org-clock-kill-emacs-query)
 +   (remove-hook 'kill-emacs-query-functions 
#'org-clock-kill-emacs-query))
 + (set symbol value))
-+  :type 'boolean)
++  :type 'boolean
++  :package-version '(Org . "9.5"))
 +
  (defvar org-clock-in-prepare-hook nil
"Hook run when preparing the clock.
@@ lisp/org-clock.el: (defun org-clock-load ()
 +(defun org-clock-kill-emacs-query ()
 +  "Query user when killing Emacs.
 +This function is added to `kill-emacs-query-functions'."
-+  (let ((buf (org-clock-buffer)))
++  (let ((buf (org-clocking-buffer)))
 +(when (and buf (yes-or-no-p "Clock out and save? "))
 +  (with-current-buffer buf
 +(org-clock-out)
2:  d612adc77 = 2:  16b5ee0ef org-clock: Replace org-clocking-buffer with 
org-clock-is-active
-:  - > 3:  4d463ee4b ORG-NEWS: Add entry for 
org-clock-ask-before-exiting



Culling org files

2021-03-03 Thread Samuel Wales
along lines of reducing logbook entries, i often want to reduce org
files, and i wonder if anybody already had the same desire.

here are some random ideas.  my org files are so
large i might have written this list a few times

  1) list links to duplicate headlines
  2) list links to duplicate body text
  3) list links to duplicate entries
  4) list links to duplicate entries, body text, or
 headlines using fuzzy matching
 - suppose you captured an email slightly differently a
   few times
  5) show in agenda the biggest few tasks so you can go to
 them and reduce them or doneify them
  6) (waves hands) git magic to find old entries that might
 be stale
  7) show in agenda the tasks with biggest logbook drawers
 so you can go to them and reduce them
  8) find similar body text that are in distant subtrees
 that might be candidates for refactoring using org-id
 linking
  9) show in agenda deepest olpath levels
  10) indicate deep, shallow, text-filled, etc. top levels
  11) show in agenda entries with most children
  12) archive logbook drawer entries older than 1 year
  - get rid of drawer if empty
  - put the drawer entries into a logbook drawer in a
new task, with a similar header, that then gets
doneified.  then that gets archived when you archive
stuff.
  13) operate on lines matching a pattern
  - e.g. "* [2021-02-17 Wed 20:35]  whatever" lines
might be insubstantial notes that do not need to
clutter the inactive timestamp display in the agenda
and thus should be moved to a target location with
query
  - that target location would presumably not be in an
agenda file
  14) function to lint all agenda files
  15) reduce false positives in lint

well, idk if htese are good ideas.  just thought maybe we
could form a cult of "don't let org files get too big".

-- 
The Kafka Pandemic

Please learn what misopathy is.
https://thekafkapandemic.blogspot.com/2013/10/why-some-diseases-are-wronged.html



Re: Org mode links: Open a PDF file at a given page and highlight a given string

2021-03-03 Thread Juan Manuel Macías
Hi Maxim

Thanks for your advice, which I appreciate very much.

Maxim Nikulin  writes:

> On 03/03/2021 09:31, Juan Manuel Macías wrote:
>> (start-process-shell-command "zathura" nil (concat "zathura "
>>clean-path
>>" -P "
>>pag
>>(when str
>>  (format " 
>> -f '%s' " str)))
>
> Please, do not forget to pass stings coming from user input through
> shell-quote-argument. There is combine-and-quote-strings function but 
> its docstring tells that it is not safe enough. Ideally shell should
> be completely avoided in such cases and arguments should be passed as
> a list directly to exec. https://xkcd.com/327/

So, maybe it would look better like this (`start-process' instead of
`start-process-shell-command')?:

#+begin_src emacs-lisp
(org-link-set-parameters
 "pdf-pag"
 :follow (lambda (path)
   (let ((pag (if (string-match "::\\([1-9]+\\):*:*\\(.*\\)" path)
  (format "--page=%s" (match-string 1 path))
(error "no pages")))
 (clean-path (expand-file-name (replace-regexp-in-string "::.+" 
"" path)))
 (str (when (string-match "::\\([1-9]+\\)::\\(.+\\)" path)
(format "--find=%s" (match-string 2 path)
 (if str
 (start-process "zathura" nil "/usr/bin/zathura"
clean-path
pag
str)
   (start-process "zathura" nil "/usr/bin/zathura"
  clean-path
  pag)
#+end_src

Best reagards,

Juan Manuel 



Re: Remove old clock entries

2021-03-03 Thread TRS-80

On 2021-03-01 01:20, Julien Cubizolles wrote:

I'm clocking the time spent on daily tasks like email and for that I
have a "Daily Routine" TODO entry. Clocking in this task adds a new
clock line everyday, leading to a very populated CLOCK drawer. I'd
like to limit its size by either a maximum number of clock entries
by removing the older ones or better, removing the entries older
than some date. Is there some variable to that effect ?


Not that I am aware of (anyone is welcome to correct me if I am
wrong).

Because I have similar problem, I have been thinking about this for a
while.  I am no longer clocking, but in my case I have a lot of state
change logging.  But these are similar.

I was thinking about incorporating some handling of these entries into
a custom archival function.  Which would also handle some other things
at the same time.  But so far, it's just some notes and thoughts about
desired functionality and how it might work.  And I keep monitoring
the mailing list for some better ideas.  :)

Cheers,
TRS-80



Re: Org mode links: Open a PDF file at a given page and highlight a given string

2021-03-03 Thread Maxim Nikulin

On 03/03/2021 09:31, Juan Manuel Macías wrote:

   (start-process-shell-command "zathura" nil (concat "zathura "
  clean-path
  " -P "
  pag
  (when str
(format " -f 
'%s' " str)))


Please, do not forget to pass stings coming from user input through 
shell-quote-argument. There is combine-and-quote-strings function but 
its docstring tells that it is not safe enough. Ideally shell should be 
completely avoided in such cases and arguments should be passed as a 
list directly to exec. https://xkcd.com/327/





Re: contact management in emacs

2021-03-03 Thread TRS-80

On 2021-02-28 04:06, Russell Adams wrote:

The stumbling point for me has been exporting to my mobile
phone. I'm fine with a one way sync from my BBDB/Org solution to the
phone, but I feel like I never found a good option.

Please share what you find works for you.


I never got further than reading about it, but I have done quite a lot
of that.  And it always seems like this is the stumbling block.
Especially two way sync (as I probably most often add new contacts
into my phone, when I am out and about).

OTOH, my PinePhone has just recently shipped, so perhaps having an
actual GNU/Linux phone (instead of Android) may suddenly obviate the
need for all these complicated workarounds...  I suppose I will be
interested in what sort of format the Contacts "app" will be storing
them on the PinePhone.  In fact, I think I will search for (or make) a
thread about that at Pine64 forums...

Cheers,
TRS-80



[PATCH] Reduce code duplication in ob-sql.el and ob-sqlite.el

2021-03-03 Thread Nick Savage

Hi everyone,

See the attached patch. It is a small change to reduce code duplication 
between ob-sql.el and ob-sqlite.el by reusing org-babel-sql-expand-vars 
as suggested by the FIXME in ob-sqlite.el.


Thanks,

Nick

>From 849a1b7417b39abbf0aeb1b241e890470e4111cd Mon Sep 17 00:00:00 2001
From: Nicholas Savage 
Date: Wed, 3 Mar 2021 07:47:15 -0500
Subject: [PATCH] Reduce code duplication in ob-sqlite.el and ob-sql.el

* lisp/ob-sqlite.el (org-babel-sqlite-expand-vars): removed function
to replace with ob-sql.el version
* lisp/ob-sql.el (org-babel-sql-expand-vars): updated to support
expanding sqlite vars
---
 lisp/ob-sql.el| 15 +++
 lisp/ob-sqlite.el | 24 +++-
 2 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
index 68d5ddd0a..b1c6920cb 100644
--- a/lisp/ob-sql.el
+++ b/lisp/ob-sql.el
@@ -350,8 +350,13 @@ SET COLSEP '|'
 	 (org-babel-pick-name (cdr (assq :rowname-names params))
 			  (cdr (assq :rownames params
 
-(defun org-babel-sql-expand-vars (body vars)
-  "Expand the variables held in VARS in BODY."
+(defun org-babel-sql-expand-vars (body vars  sqlite)
+  "Expand the variables held in VARS in BODY.
+
+If SQLITE has been provided, prevent passing a format to
+`orgtbl-to-csv'.  This prevents overriding the default format, which if
+there were commas in the context of the table broke the table as an
+argument mechanism."
   (mapc
(lambda (pair)
  (setq body
@@ -362,9 +367,11 @@ SET COLSEP '|'
   (let ((data-file (org-babel-temp-file "sql-data-")))
 (with-temp-file data-file
   (insert (orgtbl-to-csv
-   val '(:fmt (lambda (el) (if (stringp el)
+   val (if sqlite
+   nil
+ '(:fmt (lambda (el) (if (stringp el)
   el
-(format "%S" el)))
+(format "%S" el
 data-file)
 (if (stringp val) val (format "%S" val
 	body)))
diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el
index 6e21fa9fd..2ec9deb78 100644
--- a/lisp/ob-sqlite.el
+++ b/lisp/ob-sqlite.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 (require 'ob)
+(require 'ob-sql)
 
 (declare-function org-table-convert-region "org-table"
 		  (beg0 end0  separator))
@@ -51,8 +52,8 @@
 
 (defun org-babel-expand-body:sqlite (body params)
   "Expand BODY according to the values of PARAMS."
-  (org-babel-sqlite-expand-vars
-   body (org-babel--get-vars params)))
+  (org-babel-sql-expand-vars
+   body (org-babel--get-vars params) t))
 
 (defvar org-babel-sqlite3-command "sqlite3")
 
@@ -110,25 +111,6 @@ This function is called by `org-babel-execute-src-block'."
 	   (org-babel-sqlite-offset-colnames
 	(org-table-to-lisp) headers-p)))
 
-(defun org-babel-sqlite-expand-vars (body vars)
-  "Expand the variables held in VARS in BODY."
-  ;; FIXME: Redundancy with org-babel-sql-expand-vars!
-  (mapc
-   (lambda (pair)
- (setq body
-	   (replace-regexp-in-string
-	(format "$%s" (car pair))
-	(let ((val (cdr pair)))
-  (if (listp val)
-  (let ((data-file (org-babel-temp-file "sqlite-data-")))
-(with-temp-file data-file
-  (insert (orgtbl-to-csv val nil)))
-data-file)
-(if (stringp val) val (format "%S" val
-	body)))
-   vars)
-  body)
-
 (defun org-babel-sqlite-table-or-scalar (result)
   "If RESULT looks like a trivial table, then unwrap it."
   (if (and (equal 1 (length result))
-- 
2.20.1



Re: greedy substitution in org-open-file

2021-03-03 Thread Maxim Nikulin

Discussion of the original patch:
https://orgmode.org/list/4b51d104.9090...@jboecker.de/T/#u
https://lists.gnu.org/archive/html/emacs-orgmode/2010-01/msg00450.html

https://orgmode.org/list/4bb9c078.9050...@jboecker.de/

The patch may make it a little easier to break things by
misconfiguring org-file-apps.





Re: Org mode links: Open a PDF file at a given page and highlight a given string

2021-03-03 Thread Maxim Nikulin

On 03/03/2021 05:36, Kyle Meyer wrote:

Rodrigo Morales writes:

[...]

+ create a Org link to specific pages of a PDF and highlight a given
   string.

#+begin_src emacs-lisp :results silent
(setq org-file-apps
   '(("\\.pdf::\\([0-9]+\\)::\\([^:]+\\)\\'" . "zathura -P %1 -f %2 %s")))
#+end_src

The following link must open the PDF at a given page and highlight the
given string. However, I'm getting the following error (see the
=#+begin_example= block below.)

[[file:~/Downloads/grub.pdf::95::do]]


Correct link should be [[info:grub#true]] (a joke, at least a kind of).

Actually I never considered search string for highlighting of particular 
text, so thank you for the hint. Browsers could generate (mutually 
incompatible) link to particular rectangle. With xpopple (fork of old 
xpdf) it is possible to send command to select region.


However I think it is better to use logical links instead of page numbers:

   okular --find do ~/Downloads/grub.pdf'#true'
   xpdf ~/Downloads/grub.pdf +true

Unfortunately firefox replaces "#" to percent-encoded sequence in 
command line argument and could not find the file. It requires editing 
in address bar.



#+begin_example
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
   replace-match(nil t t "zathura -P 95 -f %2 
/home/username/Downloads/grub")


I haven't looked at this closely or tried to trigger the error, but an
in-flight patch is touching this area
().  I've yet to
revisit it to address Maxim's helpful feedback, but I hope to soon and
will look at this error then too.


Kyle, your patch works for such handlers. This case is another argument 
to replace all substitutions in a single pass. Global state (match data) 
is the source of the problem.


I am attaching informal single-line patch for quick plumbing. 
Alternative is to use save-match-data around string-match inside the loop.
diff --git a/lisp/org.el b/lisp/org.el
index fd6226702..f45adb308 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8757,8 +8757,8 @@ If the file does not exist, throw an error."
   (save-match-data
 	(let ((match-index 1)
 	  (number-of-groups (- (/ (length link-match-data) 2) 1)))
-	  (set-match-data link-match-data)
 	  (while (<= match-index number-of-groups)
+	(set-match-data link-match-data)
 	(let ((regex (concat "%" (number-to-string match-index)))
 		  (replace-with (match-string match-index dlink)))
 	  (while (string-match regex cmd)