Insert PROPERTIES drawer after heading creation

2020-03-10 Thread Lawrence Bottorff
I want to insert upon creating a heading a PROPERTIES drawer. So far I have
this

(defadvice org-insert-heading (after add-id-stuff activate)
  (template-myid))

(defun template-myid ()
  (insert "\n:PROPERTIES:\n:TIME: "
  (substring (format "%s" (format-time-string "%Y-%m-%dT%H:%M:%S")))
  "\n:VERTEX: "
  (substring (format "%s" (shell-command "uuidgen" t)))
  "\n:EDGES:  \n:END:"))

This is working -- sort of. My problem is the uuid is getting thrown
around. The output looks like this

* Heading
:PROPERTIES:
:TIME: 2020-03-10T23:34:17
:VERTEX: 12836
:EDGES:
:END:32bf9499-f9e2-49d9-b8e7-9edb40272411

Not sure how to make this behave.

LB


Re: Bug: HTML not formatted correctly from R source code block [9.3.6 (9.3.6-23-g01ee25-elpaplus @ /home/opdfa/.emacs.d/elpa/org-plus-contrib-20200309/)]

2020-03-10 Thread Steven Delean
Hi Jack,

Thanks for your response.

Yes, I am using :session evaluation here, set using #+PROPERTY:

However, ":results value html" does not work for me. In fact, this produces no
table output at all in the resulting exported html file.

The output sent to the R :session buffer is printed correctly (when using
either :results value html or :results output html). As you say, it is the
exporter that is removing ">" from the output.

If I remove :session evaluation, I also get no output at all from these code
blocks in the exported html.

The change has been introduced within the last 12 months, as my scripts
exported with correct html formatting when I used them for last years' classes.

Best regards,
Steve

On Tue, 10 Mar 2020 17:17:48 -0700
Jack Kamm  wrote:

> Hi Steve,
>
> Steven Delean  writes:
>
> > HTML table produced from a source code block (using R code) does not display
> > because html code is not formatted correctly in the exported html output.
>
> I believe this is the same issue as reported here:
> https://lists.gnu.org/archive/html/emacs-orgmode/2020-02/msg00267.html
>
> Though, that thread was for ":session" blocks, and it's unclear whether
> you're using session or non-session evaluation here.
>
> Anyways, that thread suggests that ":results value html" works
> correctly, does switching to that work for you?
>
> If I'm correct, the basic problem is that ob-R tries to remove
> interactive shell prompts like ">" from the output. This can also cause
> other problems. I think it can be fixed by changing ob-R to use
> `ess-eval-region' to evaluate code, I'll try to submit a patch for this
> after 9.4 is released.



Clock connection between the files

2020-03-10 Thread Vladimir Nikishkin
Hello, everyone.

I have a strange situation. I have a file where I track my used time.
I have another file, in which I write a literate-style book. So I
clock-in in the first file, then open the second one and start
working.

Recently I wrote some terrible code which made my second file blow up
in size to 19 Mb, and I had to kill Emacs.

After restarting Emacs, I wanted to clock-in into the dangling clock
in the first file, but when I type C-c C-x C-i, (!) Emacs asks whether
to open the second file, warning that it is large.
The actual message is "File file2.org is large (19.7M), really open? (y, or n)"

How come org knows the connection between the first and the second
file? There are not any references to the second file in the first one
whatsoever.

Thanks everyone.

-- 
Yours sincerely, Vladimir Nikishkin



Re: Bug: HTML not formatted correctly from R source code block [9.3.6 (9.3.6-23-g01ee25-elpaplus @ /home/opdfa/.emacs.d/elpa/org-plus-contrib-20200309/)]

2020-03-10 Thread Jack Kamm
Hi Steve,

Steven Delean  writes:

> HTML table produced from a source code block (using R code) does not display
> because html code is not formatted correctly in the exported html output.

I believe this is the same issue as reported here:
https://lists.gnu.org/archive/html/emacs-orgmode/2020-02/msg00267.html

Though, that thread was for ":session" blocks, and it's unclear whether
you're using session or non-session evaluation here.

Anyways, that thread suggests that ":results value html" works
correctly, does switching to that work for you?

If I'm correct, the basic problem is that ob-R tries to remove
interactive shell prompts like ">" from the output. This can also cause
other problems. I think it can be fixed by changing ob-R to use
`ess-eval-region' to evaluate code, I'll try to submit a patch for this
after 9.4 is released.



Re: [PATCH] strike-through text in tables

2020-03-10 Thread Bastien
Hi Mark,

"Mark E. Shoulson"  writes:

> I didn't see a response to this, and I hope it's just because I sent
> it wrongly or something.  If not, is there something amiss with this?

I'm late in reading the mailing list for a week or so, but I'll handle
this (and other issues before 9.4) over the week-end.

Thanks for your patience,

-- 
 Bastien



[PATCH] strike-through text in tables

2020-03-10 Thread Mark E. Shoulson
I didn't see a response to this, and I hope it's just because I sent it 
wrongly or something.  If not, is there something amiss with this?


Make a org-mode table.  In one of the cells of the table, have some text 
that is +struck out+.  Note that the struck-out text is default text 
color (black, for me), and not org-table text color (blue, for me). 
It's even worse if you're running org-variable-pitch-mode, because the 
text also won't be set in a fixed-pitch face, and so will screw up the 
alignment of table text.  I found out why.


When org-do-emphasis-faces constructs the new face that it applies to 
the text, it passes the lookup value from the org-emphasis-alist to 
font-lock-prepend-text-property, which makes a list, composing it with 
the existing face.  This would fail for strike-though mode in a table, 
since the org-emphasis-alist lookup would return (:strike-through t), 
resulting in a face of (:strike-through t org-table), which is an 
invalid face, and then emacs has no choice but to render it unfaced.


Attaching a patch for the issue.  Rather than try to figure out how to 
make org-do-emphasis-faces somehow smart enough to deal with this 
situation (I'm not sure it's possible, in general), I took the easy way 
out and defined an org-strike-through face which can be used in 
org-emphasis-alist.



Humbly submitted for your approval...


~mark
From 9a489ddf9d411bfc907a5b765d015e757b0b6903 Mon Sep 17 00:00:00 2001
From: "Mark E. Shoulson" 
Date: Thu, 5 Mar 2020 10:03:37 -0500
Subject: [PATCH] org-faces.el: Add org-strike-through face

org-faces.el: Create org-strike-through face.
org.el: Use org-strike-through-face in org-emphasis-alist.
---
 lisp/org-faces.el | 4 
 lisp/org.el   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index d78b606ec..107ea9763 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -427,6 +427,10 @@ For source-blocks `org-src-block-faces' takes precedence."
   :group 'org-faces
   :version "22.1")
 
+(defface org-strike-through '((t (:strike-through t)))
+  "Face for struck-through text."
+  :group 'org-faces)
+
 (defface org-quote '((t (:inherit org-block)))
   "Face for #+BEGIN_QUOTE ... #+END_QUOTE blocks.
 Active when `org-fontify-quote-and-verse-blocks' is set."
diff --git a/lisp/org.el b/lisp/org.el
index 31133c554..8b27e4708 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3677,7 +3677,7 @@ You need to reload Org or to restart Emacs after setting 
this.")
 ("_" underline)
 ("=" org-verbatim verbatim)
 ("~" org-code verbatim)
-("+" (:strike-through t)))
+("+" org-strike-through))
   "Alist of characters and faces to emphasize text.
 Text starting and ending with a special character will be emphasized,
 for example *bold*, _underlined_ and /italic/.  This variable sets the
-- 
2.24.1



Nicer export of an ipython-notebook style file

2020-03-10 Thread Dima Kogan
Hi.

Recently I used org-babel to create documentation for a python plotting
library. The end-product of this documentation is a sequence of code
snippets and images (the result of evaluating the snippets).

A wrinkle is that I didn't want to use org to do the export. I'd use org
to generate all the images, and then push the .org to github, and use
its (half-assed) renderer to display the results.

This mostly worked out of the box, but some elisp was needed to get this
done fully. So this email is meant to

1. Ask the question "what is the right way to have done this?"

2. Talk about the elisp I wrote to get this done, and maybe get some of
   it merged upstream

The final product lives here:

  https://github.com/dkogan/gnuplotlib/blob/master/guide/guide.org

The big "init" block at the end is the emacs lisp in question. I can't
get github to not display it, but that's a separate thing.

Now, each required piece, one at a time.


Each python block needs to know the file it should write the results to.
Org and python need to agree about this. It looks like some org-babel
backends do this (gnuplot for example), but in general there's no way. I
wrote a lisp thing to make ALL the org-babel headers for that snippet
available to the python block in a dict called "_org_babel_params". So
the python code writes its output to _org_babel_params['_file']. Clearly
this is specific to python, but any backend that has any sort of
associative array could maybe support something like this. The code:

  (defun dima-org-babel-python-var-to-python (var)
"Convert an elisp value to a python variable.
Like the original, but supports (a . b) cells and symbols
"
(if (listp var)
(if (listp (cdr var))
(concat "[" (mapconcat #'org-babel-python-var-to-python var ", ") 
"]")
  (format "\"\"\"%s\"\"\"" var))
  (if (symbolp var)
  (format "\"\"\"%s\"\"\"" var)
(if (eq var 'hline)
org-babel-python-hline-to
  (format
   (if (and (stringp var) (string-match "[\n\r]" var)) "\"\"%S\"\"" 
"%S")
   (if (stringp var) (substring-no-properties var) var))
  (defun dima-alist-to-python-dict (alist)
"Generates a string defining a python dict from the given alist"
(let ((keyvalue-list
   (mapcar (lambda (x)
 (format "%s = %s, "
 (replace-regexp-in-string
  "[^a-zA-Z0-9_]" "_"
  (symbol-name (car x)))
 (dima-org-babel-python-var-to-python (cdr x
   alist)))
  (concat
   "dict( "
   (apply 'concat keyvalue-list)
   ")")))
  (defun dima-org-babel-python-pass-all-params (f params)
(cons
 (concat
  "_org_babel_params = "
  (dima-alist-to-python-dict params))
 (funcall f params)))
  (advice-add
   #'org-babel-variable-assignments:python
   :around #'dima-org-babel-python-pass-all-params)

Now that org-babel can tell python where to write its output, we need to
tell org-babel this. I don't actually care what the output file is
called, as long as it's unique. So each of my org-babel snippets does
not specify the :file at all, instead I advice
org-babel-execute-src-block to set a :file with "guide-%d.svg" where the
%d is an integer that's incremented with each block:

  (defun dima-org-babel-python-unique-plot-filename
  (f &optional arg info params)
(funcall f arg info
 (cons (cons ':file
 (format "guide-%d.svg"
 (condition-case nil
 (setq dima-unique-plot-number (1+ 
dima-unique-plot-number))
   (error (setq dima-unique-plot-number 0)
   params)))
  (advice-add
   #'org-babel-execute-src-block
   :around #'dima-org-babel-python-unique-plot-filename)

I'd like the count to start from 0 each time I (org-babel-execute-buffer):

  (defun dima-reset-unique-plot-number
  (&rest args)
  (setq dima-unique-plot-number 0))
  (advice-add
   #'org-babel-execute-buffer
   :after #'dima-reset-unique-plot-number)


Was there a better way to do this? Any of these advices upstreamable?

Thanks.



Re: results block doesn't get replaced when doing :results raw

2020-03-10 Thread Nick Dokos
George Mauer  writes:

> I've seen this happening a lot in a variety of modes. When I do `:results 
> raw`, on subsequent 
> evaluations, rather than replacing the results block, it gets appended to.
>
> This is almost never what I want. I remember seeing some use of `:results raw 
> replace` in some manual
> or another but that never really seems to work for me.
>
> Is there a property or something that can be set to always replace?
>

That's expected: with `:results raw', org-babel does not know where
the results end, since there is no marker, so it cannot clear them
before producing the new results  - it just puts them right after the
`#+RESULTS:' line.

Why are you using `raw'? Can you use some other format (e.g. `drawer'
or `example') instead?

-- 
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler




ob-sql.el: org-babel-process-file-name for MSSQL

2020-03-10 Thread Johan W . Klüwer
I need to query MS Sql Server (running in Docker, Ubuntu) from org-babel.
The file name for temporary files that ob-sql assembles doesn't work -- we
get, e.g.,

  c\:/tmp/babel-Pey8i9/sql-in-dhrGdF

which produces the error

  Sqlcmd: Error: Error occurred while opening or operating on file c:
(Reason: Access is denied).

while the following string works (use backslashes, add quotes).

  "c:\tmp\babel-Pey8i9\sql-in-yQfz4K"


I'm not sure of the best way to submit this. The following change to
ob-sql.el works for me, but maybe it wouldn't in other setups with Sql
Server.

   (`mssql (format "sqlcmd %s -s \"\t\" %s -i \"%s\" -o \"%s\""
   (or cmdline "")
   (org-babel-sql-dbstring-mssql
dbhost dbuser dbpassword database)
   (org-babel-sql-convert-standard-filename
 (replace-regexp-in-string "/" (regexp-quote "\\")
   (replace-regexp-in-string "c" "c"
   (org-babel-process-file-name in-file
   (org-babel-sql-convert-standard-filename
 (replace-regexp-in-string "/" (regexp-quote "\\")
   (replace-regexp-in-string "c" "c"
(org-babel-process-file-name out-file))


Johan


Re: Bug: org-highest-priority not defined [9.3.6 (release_9.3.6-399-ge6df03 @ /home/n/.emacs.d/straight/build/org/)]

2020-03-10 Thread No Wayman
Proposed patch:
diff --git a/lisp/org.el b/lisp/org.el
index 31133c554..7b7e4c80a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -2383,7 +2383,7 @@ set a priority."
   :group 'org-priorities
   :type 'boolean)

-(defalias 'org-highest-priority 'org-priority-highest)
+(defvaralias 'org-highest-priority 'org-priority-highest)

 (defcustom org-priority-highest ?A
   "The highest priority of TODO items.
@@ -2394,7 +2394,7 @@ Must be smaller than `org-priority-lowest'."
  (character :tag "Character")
  (integer :tag "Integer (< 65)")))

-(defalias 'org-lowest-priority 'org-priority-lowest)
+(defvaralias 'org-lowest-priority 'org-priority-lowest)
 (defcustom org-priority-lowest ?C
   "The lowest priority of TODO items.
 A character like ?A, ?B, etc., or a numeric value like 1, 2, etc.
@@ -2404,7 +2404,7 @@ Must be higher than `org-priority-highest'."
  (character :tag "Character")
  (integer :tag "Integer (< 65)")))

-(defalias 'org-default-priority 'org-priority-default)
+(defvaralias 'org-default-priority 'org-priority-default)
 (defcustom org-priority-default ?B
   "The default priority of TODO items.
 This is the priority an item gets if no explicit priority is given.



On Sat, Feb 29, 2020 at 11:35 PM No Wayman 
wrote:

> Actually, on closer inspection. Shouldn't:
>
> (defalias 'org-highest-priority 'org-priority-highest)
>
> be
>
> (defvaralias ...)?
>
> On Sat, Feb 29, 2020 at 8:09 PM No Wayman 
> wrote:
>
>> After updating Org, I'm  hitting errors for an undefined
>> `org-highest-priority'.
>> I see that this is an alias for `org-priority-highest', but
>> describe-function (and I'm not sure why it's describe-function vs
>> describe-variable) dutifully reports:
>>
>>  org-highest-priority is an alias for ‘org-priority-highest’,
>>  which is not
>>  defined. Please make a bug report.
>>
>>  Not documented.
>>
>> My first hunch is that this is due to a mixed installation of Org,
>> but I'm having trouble diagnosing this. I've installed
>> org-plus-contrib using the straight package manager.
>> I've ensured that Org is not loaded before/during upgrading Org.
>> (locate-library "org") points to the correct file:
>>
>>  "/home/n/.emacs.d/straight/build/org/org.elc"
>>
>> In the src elisp file,
>> /home/n/.emacs.d/straight/repos/org/lisp/org.el there defalias is
>> there as I would expect:
>>
>> (defalias 'org-highest-priority 'org-priority-highest)
>>
>> My usual technique for debugging this is evaling:
>>
>>   (eval-after-load "org"
>> '(debug))
>>
>> prior to loading Org. However, in this case it looks like it's
>> loading the proper file:
>>
>> Debugger entered: nil
>>   (closure (t) nil (debug))()
>>   funcall((closure (t) nil (debug)))
>>   mapc(funcall ((closure (t) nil (debug)) (closure (t) nil
>>   (add-to-list 'org-src-lang-modes '("php" . php))) (closure (t)
>>   nil (add-to-list 'org-src-lang-modes '("redis" . redis)
>>   do-after-load-evaluation("/home/n/.emacs.d/straight/build/org/org.elc")
>>   require(org)
>>   byte-code("\300\301!\210\300\302!\210\300\303!\207" [require
>>   cl-lib org org-refile] 2)
>>   autoload-do-load((autoload "org-capture" 1424805 t nil)
>>   org-capture)
>>   command-execute(org-capture)
>>
>> I plan on reporting with the author of straight.el, too. Just
>> following through on the describe-function message here.
>> Not sure how to proceed with debugging. Apologies if this is
>> noise.
>>
>>
>> Emacs  : GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, X
>> toolkit, cairo version 1.17.3, Xaw3d scroll bars)
>>  of 2020-02-23
>> Package: Org mode version 9.3.6 (release_9.3.6-399-ge6df03 @
>> /home/n/.emacs.d/straight/build/org/)
>>
>> current state:
>> ==
>> (setq
>>  org-src-mode-hook '(org-src-babel-configure-edit-buffer
>>  org-src-mode-configure-edit-buffer
>>  doom-modeline-set-org-src-modeline)
>>  org-link-shell-confirm-function 'yes-or-no-p
>>  org-metadown-hook '(org-babel-pop-to-session-maybe)
>>  org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
>>  org-refile-targets '((org-agenda-files :maxlevel . 20)
>>  (my/org-files-list :maxlevel . 20))
>>  org-enforce-todo-dependencies t
>>  org-agenda-category-icon-alist '(("[Ww]ork"
>>(#("" 0 1
>>   (rear-nonsticky t display
>>   (raise -0.24) font-lock-face
>>(:family "FontAwesome"
>>:height 1.2) face
>>(:family "FontAwesome"
>>:height 1.2))
>>   )
>> )
>>nil nil :ascent center)
>>   ("[Rr]efile"
>>(#("" 0 1
>>   (rear-nonsticky t display
>>

Re: Turn on org-num-mode in init?

2020-03-10 Thread Lawrence Bottorff
Good. That worked. I just put

(require 'org-num)
(add-hook 'org-mode-hook #'org-num-mode)

inside my use-package org 's (massive) :config


On Tue, Mar 10, 2020 at 1:28 AM Eric S Fraga  wrote:

> On Monday,  9 Mar 2020 at 23:31, Lawrence Bottorff wrote:
> > I've tried a few variations of trying to turn on org-num-mode (which now
> > comes standard in org, correct?) in my init, but I keep getting an error
> > buffer upon a fresh startup
>
> Maybe show us what you have right now instead of what others have done?
>
> In any case, this one:
>
> > (use-package org-num
> >   :load-path "lisp/"
> >   :after org
> >   :hook (org-mode . org-num-mode))
>
> should work, as far as I can tell although I don't use use-package at
> all.  Have you tried with a reduced .emacs?
>
> You could try the following:
>
> (require 'org)
> (require 'org-num)
> (add-hook 'org-mode-hook #'org-num-mode)
>
> --
> : Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-354-g9d5880
>


results block doesn't get replaced when doing :results raw

2020-03-10 Thread George Mauer
I've seen this happening a lot in a variety of modes. When I do `:results
raw`, on subsequent  evaluations, rather than replacing the results block,
it gets appended to.

This is almost never what I want. I remember seeing some use of `:results
raw replace` in some manual or another but that never really seems to work
for me.

Is there a property or something that can be set to always replace?


Re: org-link containing square brackets

2020-03-10 Thread Eric S Fraga
On Tuesday, 10 Mar 2020 at 13:33, Joseph Vidal-Rosset wrote:
> I wonder more and more if gnus in imap is the adequate tool to keep
> tracks of email via org-mode links. All opinions of this topic are
> welcome, of course, because I have to take a decision: to gnus or not
> to gnus... :) 

The real question is to Google or not to Google.

I recently moved away from Google (due to the insanity that is Brexit
and losing the GDPR protection) for all of my personal email and will
continue to use gnus as it's the best MUA bar none.  Google does not
really grok IMAP.  Go for a standards based provider and, arguably, one
that you pay for explicitly (as opposed to implicitly as you do for
Google's gmail).

Just my 2¢.

And, to keep this on-topic, with a proper IMAP provider, org links to
emails work just fine.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-354-g9d5880



Re: org-link containing square brackets

2020-03-10 Thread Joseph Vidal-Rosset
Le   mar.   03/10/20   mars   2020  à   10:47:03   ,   Nicolas   Goaziou
 a envoyé ce message:
> Hello,
>
> Joseph Vidal-Rosset  writes:
>
>> I sent this email to this list:
>>
>> https://lists.gnu.org/archive/html/emacs-orgmode/2019-07/msg00123.html
>>
>> Unfortunately, the code of hs/replace function that contains
>>
>> %5BGmail%5D/
>
> See ORG-NEWS for Org 9.3. I think this should be \[Gmail\]/

Hello Nicolas,

Many thanks for your very helpful email. In fact,
 \[Gmail\]/
 broke the link, but
  \\[Gmail\\]/
  works (very logically, it is related with the syntax of org-export).

Now, I meet a new problem that is not an org-mode issue, but gnus's: the
link works, but gnus  declare that the article has expired.  :( and I do
not  understand why.  I wonder  more and  more if  gnus in  imap is  the
adequate tool to  keep tracks of email via org-mode  links. All opinions
of this topic are welcome, of course, because I have to take a decision:
to gnus or not  to gnus... :) But I will not open  a new thread for this
question. 
 
All the best, et encore merci Nicolas !

Jo. 



Re: org-link containing square brackets

2020-03-10 Thread Nicolas Goaziou
Hello,

Joseph Vidal-Rosset  writes:

> I sent this email to this list:
>
> https://lists.gnu.org/archive/html/emacs-orgmode/2019-07/msg00123.html
>
> Unfortunately, the code of hs/replace function that contains
>
> %5BGmail%5D/

See ORG-NEWS for Org 9.3. I think this should be \[Gmail\]/

Regards,

-- 
Nicolas Goaziou



org-link containing square brackets

2020-03-10 Thread Joseph Vidal-Rosset
Hi everybody,

I sent this email to this list:

https://lists.gnu.org/archive/html/emacs-orgmode/2019-07/msg00123.html

Unfortunately, the code of hs/replace function that contains

%5BGmail%5D/

to get [Gmail]/   in the link does not work anymore for few months
now: in the org-link  the square brackets do not appear and of course
gnus does not find the email ... :(

I have searched but I do not find the solution. (Maybe trying
wanderlust or mu4e, but I remain reluctant for various reasons...)

If you can help me, thanks in advance,

Best wishes,

Jo.