‘org-test-with-temp-text’ fails weirdly

2020-05-06 Thread Göktuğ Kayaalp
Hello,

I was trying to have spurious indentation removed from Python source
blocks before execution so that such blocks can be indented in Org mode
buffers.  I managed to do so successfully, but some tests keep failing
and I believe it’s the test runner that’s the culprit. With the attached
patch applied, I’ve observed successful execution when manually trying
test cases similar to those in test-ob-python.el, indented or not. But
the following tests fail with ‘(args-out-of-range "return x" 42 43)’
errors:

   FAILED  test-ob-python/colnames-nil-header-argument
   FAILED  test-ob-python/colnames-no-header-argument
   FAILED  test-ob-python/colnames-yes-header-argument

(9 tests fail without this patch, the other 6 is irrelevant and do fail
when I test w/o the patch too, on commit b171ff02f.)

I think the cause is the modifications to the code blocks body (deletion
of spurious indentation from an indented src block), but I’m not sure
how exactly.

This is weird because the in-buffer text doesn’t change.

In any case I’m also proposing the attached patch as a new feature.
Could start a new thread for it if necessary.

P.S.: please keep me in the CC in your replies, I’m not subscribed to
the mailing list.

-- 
İ. Göktuğ Kayaalp / @cadadr / 
pgp:   024C 30DD 597D 142B 49AC 40EB 465C D949 B101 2427

>From 88ad28dce8e0111c10ca18db5f58d35924112441 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=B0=2E=20G=C3=B6ktu=C4=9F=20Kayaalp?= 
Date: Thu, 7 May 2020 03:11:50 +0300
Subject: [PATCH] lisp/ob-python.el: remove spurious indentation before
 evaluation

---
 lisp/ob-python.el | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index dbcfac08d..42bb47f73 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -69,6 +69,24 @@ This will typically be either `python' or `python-mode'."
   :package-version '(Org . "8.0")
   :type 'symbol)
 
+(defun org-babel-python--clean-spurious-indentation (body)
+  (let* ((extra-indentation
+	  (save-match-data
+	(string-match "\\`\\([ \t]+\\)" body)
+	(match-string 1 body)))
+	 (xlen (length extra-indentation)))
+(if (zerop xlen)
+	body
+  (mapconcat
+   (lambda (line) (if (<= (length line) xlen)
+			  line
+			(if (string= extra-indentation
+ (substring line 0 xlen))
+			(substring line xlen)
+			  line)))
+   (split-string body "\n")
+   "\n"
+
 (defun org-babel-execute:python (body params)
   "Execute a block of Python code with Babel.
 This function is called by `org-babel-execute-src-block'."
@@ -84,7 +102,8 @@ This function is called by `org-babel-execute-src-block'."
 	 (preamble (cdr (assq :preamble params)))
  (full-body
 	  (org-babel-expand-body:generic
-	   (concat body (if return-val (format "\nreturn %s" return-val) ""))
+	   (concat (org-babel-python--clean-spurious-indentation body)
+		   (if return-val (format "\nreturn %s" return-val) ""))
 	   params (org-babel-variable-assignments:python params)))
  (result (org-babel-python-evaluate
 		  session full-body result-type result-params preamble)))
-- 
2.17.1



Re: Inserting org-mode heading links the org-refile way

2020-05-06 Thread Josh Moller-Mara
Hi,

Here's an example of how to create an ivy prompt that inserts links.

It isn't exactly what you're looking for, as it doesn't hijack
`org-insert-link` functionality, nor does it specifically use
`org-refile-target-verify-function` to do filtering.

Instead, this uses org-ql to select TODO headers with a level of at
least 3. org-ql will cache queries in a manner similar to the initial
collecting of org-refile targets. You can add other filter criteria
using org-ql's sexp query syntax. You can also replace the
`(org-agenda-files)` to be some expression that returns the specific
list of files you're interested in.

(defun jmm/org-ql-ivy-prompt-for-link ()
  "Select a todo header with ivy and insert its link"
  (interactive)
  (ivy-read "Link:"
(->> (org-ql-select (org-agenda-files)
   '(and (todo)
 (level >= 3)
 (not (tags "ARCHIVE")))
   :action 'element-with-markers)
 (-map #'org-ql-view--format-element))
:action (lambda (x)
  (let ((org-id-link-to-org-use-id t)) ; Add an ID if it 
doesn't exist
(insert
 (org-with-point-at (get-text-property 0 'org-hd-marker 
x)
   (org-store-link nil)))

Note: This also uses dash.el functions/macros. You can replace that as
needed.

Best,
Josh

Daryl Manning  writes:

> This looks impressive, and is *similar* to the effect I am going for, but
> what I am looking at is intercepting the `org-insert-link` functionality
> (or replacing it) with the ability to insert a link from the global
> filter-and-select interface via ivy for `org-refile`. So, in other words,
> global access to the (say 3 levels down) headings and files available
> through the ivy interface (which further allows me to filter that down).
>
> This would give me the ability to arbitrarily add links across all files
> (and particularly handy with org-contact for adding in links in cal entries
> for meetings).  Since the viy interface seems to work fine for refiling
> tasks (except for initial load of refile targets), it seems it'd be
> sufficiently performant.
>
> Daryl.



Proper links for Latex documentation in manual

2020-05-06 Thread John Hendy
Greetings,

I was looking to see if there was a way to rotate images and refresh
myself on available attr_latex commands. Google took me here:

https://orgmode.org/manual/LaTeX-Export.html

Clicking "Images in LaTeX export" points here:

https://orgmode.org/manual/LaTeX-Export.html#Images-in-LaTeX-export

But nothing happens, I just stay on that page. I got to the previous
link from here:

https://orgmode.org/manual/Main-Index.html

Going back and clicking the link for "Images in LaTeX export" (instead
of attr_latex as I originally clicked) has the same effect.

I'm assuming this is not the desired behavior, as the first three
links go to LaTeX relevant pages, but the rest do not.


Best regards,
John



[Patch] Do not ignore headers argument in ob-latex

2020-05-06 Thread Yuri Lensky
ob-latex default .png export completely ignored additional "headers"
arguments.


0001-lisp-ob-latex.el-Stop-ignoring-headers-argument.patch
Description: Binary data


[PATCH] Make RET and C-j obey `electric-indent-mode' in org-mode (was: Reconciling org-mode idiosyncrasies with Emacs core)

2020-05-06 Thread Kévin Le Gouguec
Hello folks,

Here's a complete patch to make RET and C-j honor electric-indent-mode
in org-mode, targeting Org's master branch.

>From ec3b06f02aa875b3c78b076e846081ce4560ec18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= 
Date: Tue, 5 May 2020 19:01:07 +0200
Subject: [PATCH] Make RET and C-j obey `electric-indent-mode'

* etc/ORG-NEWS: Announce the change.

* lisp/org-compat.el (org-return-indent): Deprecate this command.

* lisp/org-keys.el (org-mode-map): Rebind C-j to a command emulating
`electric-newline-and-maybe-indent'.

* lisp/org.el (org-cdlatex-environment-indent): Stop using the now
obsolete function.
(org--newline): New helper function.
(org-return): Use it to transparently handle `electric-indent-mode'.
(org-return-and-maybe-indent): New command to emulate
`electric-newline-and-maybe-indent' while taking care of Org special
cases (tables, links, timestamps).

* testing/lisp/test-org.el (test-org/with-electric-indent,
test-org/without-electric-indent): New tests.

* testing/org-test.el (org-test-with-minor-mode): New helper to set a
minor mode to a specific state, and reset it afterward.
---
 etc/ORG-NEWS | 33 +
 lisp/org-compat.el   |  9 +
 lisp/org-keys.el |  2 +-
 lisp/org.el  | 43 ++-
 testing/lisp/test-org.el | 76 
 testing/org-test.el  |  9 +
 6 files changed, 155 insertions(+), 17 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c10e82f53..9c7e0d604 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -215,6 +215,32 @@ configured for ClojureScript will /not/ work.
 Babel Java blocks recognize header argument =:cmdargs= and pass its
 value in call to =java=.
 
+*** =RET= and =C-j= now obey ~electric-indent-mode~
+
+Since Emacs 24.4, ~electric-indent-mode~ is enabled by default.  In
+most major modes, this causes =RET= to reindent the current line and
+indent the new line, and =C-j= to insert a newline without indenting.
+
+Org-mode now obeys this minor mode: when ~electric-indent-mode~ is
+enabled, and point is neither in a table nor on a timestamp or a link:
+
+- =RET= (bound to ~org-return~) reindents the current line and indents
+  the new line;
+- =C-j= (bound to the new command ~org-return-and-maybe-indent~)
+  merely inserts a newline.
+
+To get the previous behaviour back, disable ~electric-indent-mode~
+explicitly:
+
+#+begin_src emacs-lisp
+(add-hook 'org-mode-hook (lambda () (electric-indent-mode -1)))
+#+end_src
+
+*** New optional numeric argument for ~org-return~
+
+In situations where ~org-return~ calls ~newline~, multiple newlines
+can now be inserted with this prefix argument.
+
 ** New commands
 *** ~org-table-header-line-mode~
 
@@ -303,6 +329,13 @@ Use ~org-hide-block-toggle~ instead.
 This function was not used in the code base, and has no clear use
 either.  It has been marked for future removal.  Please contact the
 mailing list if you use this function.
+
+*** Deprecated ~org-return-indent~ function
+
+In Elisp code, use ~(org-return t)~ instead.  Interactively, =C-j= is
+now bound to ~org-return-and-maybe-indent~, which indents the new line
+when ~electric-indent-mode~ is disabled.
+
 *** Removed ~org-maybe-keyword-time-regexp~
 
 The variable was not used in the code base.
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index aae8efbd3..2b35535fa 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -678,6 +678,15 @@ an error.  Return a non-nil value when toggling is successful."
 (goto-char (match-beginning 0))
 (org-hide-block-toggle)))
 
+(defun org-return-indent ()
+  "Goto next table row or insert a newline and indent.
+Calls `org-table-next-row' or `newline-and-indent', depending on
+context.  See the individual commands for more information."
+  (declare (obsolete "use `org-return' with INDENT set to t instead."
+		 "Org 9.4"))
+  (interactive)
+  (org-return t))
+
 (defmacro org-with-silent-modifications ( body)
   (declare (obsolete "use `with-silent-modifications' instead." "Org 9.2")
 	   (debug (body)))
diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index d358da763..7c0cc9216 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -618,7 +618,7 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-k") #'org-kill-note-or-show-branches)
 (org-defkey org-mode-map (kbd "C-c #") #'org-update-statistics-cookies)
 (org-defkey org-mode-map (kbd "RET") #'org-return)
-(org-defkey org-mode-map (kbd "C-j") #'org-return-indent)
+(org-defkey org-mode-map (kbd "C-j") #'org-return-and-maybe-indent)
 (org-defkey org-mode-map (kbd "C-c ?") #'org-table-field-info)
 (org-defkey org-mode-map (kbd "C-c SPC") #'org-table-blank-field)
 (org-defkey org-mode-map (kbd "C-c +") #'org-table-sum)
diff --git a/lisp/org.el b/lisp/org.el
index 63de7306c..dbd072aff 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15580,7 +15580,7 @@ 

Re: Bug: Missing key definition for org-resolve-clocks [9.3.6 (9.3.6-25-g685b2c-elpa @ c:/users/ian/.emacs.d/elpa/org-20200316/)]

2020-05-06 Thread Ian Garmaise
Hi Kyle,

Not sure what happened, but about a month after I reported it, the key
binding started to work.
I hadn't made significant changes to my setup during that period, but maybe
some library that I had installed caused the problem.

Thanks for checking,

Best,

Ian


On Tue, May 5, 2020 at 11:38 PM Kyle Meyer  wrote:

> [ Sorry for the delayed reply. ]
>
> Ian Garmaise writes:
>
> > According to the manual section 8.4.3, org-resolve-clocks should be
> > bound to C-c C-x C-z
> >
> > This doesn't seem to be the case.
>
> That's odd.  That binding has been around for a while (f250f6beb,
> 2012-07-28) and is in the version you reported to be running:
>
>   $ git grep org-resolve-clocks 685b2c -- lisp/org-keys.el
>   685b2c:lisp/org-keys.el:(declare-function org-resolve-clocks "org"
> ( only-dangling-p prompt-fn last-valid))
>   685b2c:lisp/org-keys.el:(org-defkey org-mode-map (kbd "C-c C-x C-z")
> #'org-resolve-clocks)
>
> Perhaps there's something in your configuration that's clobbering the
> default binding.
>


-- 
=
Ian Garmaise
Consultant
Phorix Solutions Group
ia...@phorixsol.com
Toronto cell: 416.432.2251
NYC: 917.512.9535

https://www.linkedin.com/in/igarmaise/

http://www.PhorixSol.com