Re: [PATCH] ob-sql.el: Add support for SAP HANA

2021-03-16 Thread Kyle Meyer
Robin Campbell Joy writes:

> Subject: [PATCH] ob-sql.el: Add support for SAP HANA

Thanks for the update.  Pushed (b241c126b).

> diff --git a/testing/lisp/test-ob-sql.el b/testing/lisp/test-ob-sql.el
[...]
> +
> +(require 'org-test)
> +(require 'ob-sql)

I've dropped these two lines.

For the first one, currently only four test files load org-test
explicitly, while the majority of the tests rely on org-test being
loaded as part of the setup.

For the second, nearly all ob-LANG tests check whether the corresponding
ob- feature is available, signaling missing-test-dependency if it's not.
Which ob- libraries are loaded/tested can then controlled by the
Makefile variable BTEST_OB_LANGUAGES.  Explicitly loading the ob- file
goes against that setup, making the (featurep ...) check that follows
always return non-nil,

I'm guessing this line was adjusted from test-ob-sqlite, which appears
to be the one [*] ob-LANG test file that gets this wrong.  I've
pushed another commit to adjust it.

[*] I believe ob-emacs-lisp is an intended exception.

> +(unless (featurep 'ob-sql)
> +  (signal 'missing-test-dependency "Support for sql code blocks"))




Re: How to get shell source blocks to read my profile?

2021-03-16 Thread Tim Cross


George Mauer  writes:

> I do still wonder what would be the disadvantage of just configuring it to do 
> --login by default and doing all configuration in profile scripts. It would be
> unconventional yes, but it would also make dynamic scoping of environment 
> variable effectively opt-in via --noprofile rather than opt-out (which imo is
> how it should be). I would assume that uses extra resources or risks 
> improperly handling crashed processes, but I can't find anything to that 
> effect in the
> docs

The following is long, but may provide some of the context you are
looking for to help understand all the moving parts involved here. Some
of ti is not 100% accurate, but trying to be 100% accurate would make it
longer and would not necessarily help with the mental model needed to
understand how this all fits together. Hopefully, this has a reasonable
balance between accuracy and simplicity!

While there is certainly aspects of shell architecture which are less
relevant in a modern computing environment, the way it all works is
actually pretty good. It can sometimes help to remember what early Unix
environments were like and what the resource constraints were to
understand some of the design decisions. A time when memory and disk
storage was extremely expensive and in short supply, where CPUs were
slower and less capable than those commonly found in a modern washing
machine. This was a time where every CPU cycle, every memory bit and
every byte of storage had to be justified and used efficiently.

The 'login' shell actually has a special purpose and a few subtleties
associated with it that may not be obvious at first. For example, the
login shell usually records a user's login in a few system files like
wtmp and utmp. The idea is that the login shell will be the 'root' of a
user's process tree. One of its key roles is to setup the environment
which will be inherited by all the other (child) processes which the
user initiates. This includes some things which you only want run once
and processes which must run as parents to all other processes. A good
example is setting up an ssh agent and adding ssh keys to that agent.
You only want this to occur once, so you might add this to your .profile
(or whatever the shell equivalent is, such as .bash_profile or
.zsh_profile). More critical is the requirement that the ssh agent must
be run inside a parent process for child processes to be able to use it.
This means it needs to be near the 'root' login process to ensure all
children are able to take advantage of the service it provides.
(Keep in mind that some platforms, like the mac, have created a whole
new architecture for managing keys etc and even on Linux, it is rarely
necessary to run ssh-agent like we did in the 'old days' as that
functionality has been subsumed into desktop environments like gnome)

It is also here that you will define static environment variables i.e.
those which will not change during the lifetime of the session and which
are exported, meaning they are made available in the environments of
child processes. Examples are setting up things like PATH, EMAIL etc.
Some common environment variables, like USER, HOME etc are done
automatically as part of the system wide profile in /etc/profile or the
system wide path defined in /etc/paths and /etc/paths.d etc.

In addition to these static environment variables are more dynamic ones
which change and therefore need to be updated with each new shell
process. This can include variables like PWD and CWD which track the
parent and current working directory or the PS1 and PS2 variables which
contain details about your shell prompt that may include dynamic
information such as the current working directory, current date/time or
status of the git repository associated with the current working
directory. This is essentially the role fulfilled by the 'rc' files,
like .bashrc. As these dynamic enironment variables tend to only be
relevant for interactive shells, the rc file is only 'sourced' for those
shells.

When you execute a command, it creates a new process which has an
execution environment associated with it (there are some exceptions,
such as built-in shell commands that run inside the current process and
command 'modifiers' like 'exec' which replace the current process with
the command being executed). Some of these processes will be very short
lived, executing a single command or possibly run for hours, days, weeks
(such as Emacs). This process is a child process of the process which
ran/executed the command. You can use the -f (forest) switch to ps to
see the relationship between processes. Those processes in turn may
execute more child processes (such as when Emacs creates a shell process
to perform some task, like run a compilation task, spawn a shell or
terminal, etc. The environment each of these processes inherits consists
of the exported variables defined in the parent process. This is
typically all the exported variables from the login 

Re: [PATCH] ob-sql.el: Add support for SAP HANA

2021-03-16 Thread Daniele Nicolodi
Hello Robin,

from this patch I infer that you work with SAP. Can I bug you off-list
with a few questions unrelated to org-mode but related to
programmatically interact with SAP?

Thank you.

Best,
Dan

On 04/02/2021 08:55, Robin Campbell Joy wrote:
> * lisp/ob-sql.el (org-babel-execute:sql, org-babel-sql-dbstring-saphana):
> Add basic support for SAP HANA to SQL blocks
> * testing/lisp/test-ob-sql.el: Basic tests for generated db connection
> string
> 
> This change adds basic support for SAP HANA to SQL blocks by
> specifying saphana as :engine.
> 
> It also adds a new header arg `dbinstance' in order to specify the SAP
> HANA instance to connect to.
> 
> Signed-off-by: Robin Campbell Joy  >
> ---
>  lisp/ob-sql.el              |  25 ++-
>  testing/lisp/test-ob-sql.el | 382 
>  2 files changed, 406 insertions(+), 1 deletion(-)
>  create mode 100644 testing/lisp/test-ob-sql.el
> 
> diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el
> index 902194ae8..5398c85aa 100644
> --- a/lisp/ob-sql.el
> +++ b/lisp/ob-sql.el
> @@ -40,6 +40,7 @@
>  ;; - dbuser
>  ;; - dbpassword
>  ;; - dbconnection (to reference connections in sql-connection-alist)
> +;; - dbinstance
>  ;; - database
>  ;; - colnames (default, nil, means "yes")
>  ;; - result-params
> @@ -58,6 +59,7 @@
>  ;; - postgresql (postgres)
>  ;; - oracle
>  ;; - vertica
> +;; - saphana
>  ;;
>  ;; TODO:
>  ;;
> @@ -85,6 +87,7 @@
>      (dbport       . :any)
>      (dbuser       . :any)
>      (dbpassword       . :any)
> +    (dbinstance       . :any)
>      (database       . :any))
>    "SQL-specific header arguments.")
>  
> @@ -174,6 +177,18 @@ SQL Server on Windows and Linux platform."
>    (when database (format "-d %s" database
>        " "))
>  
> +(defun org-babel-sql-dbstring-saphana (host port instance user password
> database)
> +  "Make SAP HANA command line args for database connection. Pass nil to
> omit that arg."
> +  (mapconcat #'identity
> +             (delq nil
> +                   (list (when (and host port) (format "-n %s:%s" host
> port))
> +                         (when (and host (not port)) (format "-n %s" host))
> +                         (when instance (format "-i %d" instance))
> +                         (when user (format "-u %s" user))
> +                         (when password (format "-p %s"
> (shell-quote-argument password)))
> +                         (when database (format "-d %s" database
> +             " "))
> +
>  (defun org-babel-sql-convert-standard-filename (file)
>    "Convert FILE to OS standard file name.
>  If in Cygwin environment, uses Cygwin specific function to
> @@ -197,6 +212,7 @@ database connections."
>                               (:dbport . sql-port)
>                               (:dbuser . sql-user)
>                               (:dbpassword . sql-password)
> +                             (:dbinstance . sql-dbinstance)
>                               (:database . sql-database)))
>               (mapped-name (cdr (assq name name-mapping
>          (cadr (assq mapped-name
> @@ -212,6 +228,7 @@ This function is called by
> `org-babel-execute-src-block'."
>           (dbport (org-babel-find-db-connection-param params :dbport))
>           (dbuser (org-babel-find-db-connection-param params :dbuser))
>           (dbpassword (org-babel-find-db-connection-param params
> :dbpassword))
> +         (dbinstance (org-babel-find-db-connection-param params
> :dbinstance))
>           (database (org-babel-find-db-connection-param params :database))
>           (engine (cdr (assq :engine params)))
>           (colnames-p (not (equal "no" (cdr (assq :colnames params)
> @@ -276,6 +293,12 @@ footer=off -F \"\t\"  %s -f %s -o %s %s"
>        dbhost dbport dbuser dbpassword database)
>       (org-babel-process-file-name in-file)
>       (org-babel-process-file-name out-file)))
> +    (saphana (format "hdbsql %s -I %s -o %s %s"
> +     (org-babel-sql-dbstring-saphana
> +      dbhost dbport dbinstance dbuser dbpassword database)
> +     (org-babel-process-file-name in-file)
> +     (org-babel-process-file-name out-file)
> +     (or cmdline "")))
>                      (t (user-error "No support for the %s SQL engine"
> engine)
>      (with-temp-file in-file
>        (insert
> @@ -309,7 +332,7 @@ SET COLSEP '|'
>   (progn (insert-file-contents-literally out-file) (buffer-string)))
>        (with-temp-buffer
>   (cond
> - ((memq (intern engine) '(dbi mysql postgresql postgres sqsh vertica))
> + ((memq (intern engine) '(dbi mysql postgresql postgres saphana sqsh
> vertica))
>    ;; Add header row delimiter after column-names header in first line
>    (cond
>     (colnames-p
> diff --git a/testing/lisp/test-ob-sql.el b/testing/lisp/test-ob-sql.el
> new file mode 100644
> index 0..51edd2309
> --- /dev/null
> +++ b/testing/lisp/test-ob-sql.el
> @@ -0,0 +1,382 @@
> +;;; test-ob-sql.el --- tests for ob-sql.el
> +
> +;; Copyright (C) 2021 

Re: How to get shell source blocks to read my profile?

2021-03-16 Thread Nick Dokos
George Mauer  writes:

> I understand why you say that maxim but testing that this worked was the 
> first thing I did
> and it does work. I was surprised as well. I haven't debugged all the way 
> into the eval
> functions to see why this works but my guess is that the authors were pretty 
> smart about
> figuring out which executable to invoke.
>

Starting with `emacs -q' I evaluate

(setq shell-file-name "bash -i")

in the *scratch* buffer and then do `M-x shell'. I get

apply: Searching for program: No such file or directory, bash -i


If I do

(setq shell-file-name "/bin/bash -i")

I get

emacs: /bin/bash -i: No such file or directory

Process shell exited abnormally with code 127

The trouble is that `shell-file-name' may be used much more widely than you 
expect.

> As for the problem I'm trying to solve, there isn't one exactly. This is more 
> me hacking on
> something I don't fully understand because it regularly trips me up.
>
> I do still wonder what would be the disadvantage of just configuring it to do 
> --login by
> default and doing all configuration in profile scripts. It would be 
> unconventional yes, but
> it would also make dynamic scoping of environment variable effectively opt-in 
> via
> --noprofile rather than opt-out (which imo is how it should be). I would 
> assume that uses
> extra resources or risks improperly handling crashed processes, but I can't 
> find anything to
> that effect in the docs
>
> On Tue, Mar 16, 2021, 07:32 Maxim Nikulin  wrote:
>
> On 16/03/2021 00:49, George Mauer wrote:
> >    shell-file-name: "/bin/zsh -i"
>
> I am afraid, you should be prepared to face some problem accidentally.
> The value of this variable is used to execute the specified file
> ("zsh -i" in the "/bin" directory, I do not think, you have such file),
> not as a part of shell command. shell-file-name in namely file name to
> be executed with shell-command-switch as first argument (separate
> arguments, not merged into a string) to run shell commands (next 
> argument).
>
> Environment variables could be set on OS level, inside emacs
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Environment.html
> , etc. It is hard to suggest something since you have not described the
> problem you are trying to solve. Tim in details explained why you
> attempt to solve it did not work, but the problem (or the goal) is still
> unknown.
>

-- 
Nick

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




Re: Problems while trying to load feature

2021-03-16 Thread Nick Dokos
"Charles R (Charlie) Martin"  writes:

> This is a problem I’ve noticed as well. Now, I am a programmer — my
> code or it’s descendants is still in the distribution — I do update
> org mode regularly, and I get messages when I start up Emacs about
> Org mode files that can’t be loaded. I wouldn’t be surprised if the
> cause is this renaming. But honestly I stopped having time to hack
> emacs 30 years ago. Wouldn’t it be desirable if changes that aren’t
> backward-compatible included some kind of assistance for users? 
>

You probably don't want to hear this, but you will have to figure out
what those messages are telling you and fix the problems. At best,
they might be innocuous: your init file might be trying to load things
that don't exist any more. At worst, you may be running a mixed
installation: you might be loading things from various versions of Org
mode that might coexist on your system(s) (depending on how exactly
you install Org mode: if you use the version that is bundled with
emacs *only* you should not have any problems; but if you install a
more recent one from ELPA or from git, you should be careful). If you
encounter problems after the initial load, you might have a mixed
installation. See https://orgmode.org/worg/org-faq.html#mixed-install for more
details on how to check. Mixed installations are an unending source of
problems and need to be taken care of.

I install new versions of emacs and Org mode fairly frequently (every
couple of months) at which point I restart emacs to see whether any
such problems crop up. If there are, I fix them right then and there,
until I can get a clean restart. If it's not obvious, I take a look
through the etc/ORG-NEWS file, which you should have locally, but in a
pinch you can look for it online:

https://code.orgmode.org/bzg/org-mode/src/master/etc/ORG-NEWS

In particular, this is the best place for assistance with backward
incompatibilities that you mentioned above. Assuming you know which
release you came from and which release you are going to, look through
the sections describing them and all intermediate releases, to see
what backward incompatibilites were introduced and what suggested
solutions there are. As a last resort, you can always ask here. In
general, I find that fixing these problems asap is better for my
sanity.

Cleaning up your init file to get rid of the (now) useless loads is
also a good idea (even though they are innocuous): init files tend to
accumulate junk (mine has been doing that for 30 years), so getting
rid of old cruft is, for me, another essential activity to maintain a
semblance of sanity.

My $0.02, YMMV, etc.

-- 
Nick

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




Re: [PATCH] ob-sql.el: Add support for SAP HANA

2021-03-16 Thread Robin Campbell Joy
Hi,

thank you very much for you feedback.

Kyle Meyer  wrote:

>> This patch is large enough that copyright should be assigned to the FSF.
>> Assuming you haven't already, are you willing to complete the copyright
>> paperwork?

I did this before sending the patch.

>> It looks like many of the lines are corrupted by additional line breaks,
>> so it'd take a lot of manual editing to resolve the issues on my end.

I addressed your points and added the patch as an attachment to avoid
potential
issues.

 +  (mapconcat #'identity
 + (delq nil
 +   (list (when (and host port) (format "-n %s:%s" host
 port))

>> Please prefer `and' here and in other spots where the return value is of
>> interest.

>>   (and host port (format ...))

I used `when' for consistency, as all the other methods are using it, but I
don't mind changing it to `and'.


0001-ob-sql.el-Add-support-for-SAP-HANA.patch
Description: Binary data


Re: Sharing variables between source blocks without session

2021-03-16 Thread Eric S Fraga
On Tuesday, 16 Mar 2021 at 09:56, Loris Bennett wrote:
> How can I avoid having to declare the variable 'user' for both blocks?

I imagine you could use a property, as in

#+property: header-args :var user=loris

or even make it specific for the particular language.

(untested)
-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4.4-254-g37749c



Re: How to get shell source blocks to read my profile?

2021-03-16 Thread George Mauer
I understand why you say that maxim but testing that this worked was the
first thing I did and it does work. I was surprised as well. I haven't
debugged all the way into the eval functions to see why this works but my
guess is that the authors were pretty smart about figuring out which
executable to invoke.

As for the problem I'm trying to solve, there isn't one exactly. This is
more me hacking on something I don't fully understand because it regularly
trips me up.

I do still wonder what would be the disadvantage of just configuring it to
do --login by default and doing all configuration in profile scripts. It
would be unconventional yes, but it would also make dynamic scoping of
environment variable effectively opt-in via --noprofile rather than opt-out
(which imo is how it should be). I would assume that uses extra resources
or risks improperly handling crashed processes, but I can't find anything
to that effect in the docs

On Tue, Mar 16, 2021, 07:32 Maxim Nikulin  wrote:

> On 16/03/2021 00:49, George Mauer wrote:
> >shell-file-name: "/bin/zsh -i"
>
> I am afraid, you should be prepared to face some problem accidentally.
> The value of this variable is used to execute the specified file
> ("zsh -i" in the "/bin" directory, I do not think, you have such file),
> not as a part of shell command. shell-file-name in namely file name to
> be executed with shell-command-switch as first argument (separate
> arguments, not merged into a string) to run shell commands (next argument).
>
> Environment variables could be set on OS level, inside emacs
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Environment.html
> , etc. It is hard to suggest something since you have not described the
> problem you are trying to solve. Tim in details explained why you
> attempt to solve it did not work, but the problem (or the goal) is still
> unknown.
>
>
>


Re: [PATCH] Re: Bug: Plain https links with brackets are not recognised [9.4.4 (release_9.4.4-625-g763c7a @ /home/yantar92/.emacs.d/straight/build/org/)]

2021-03-16 Thread Ihor Radchenko
Maxim Nikulin  writes:

> I have tried to compare current, your, and a little modified your 
> regexps on several synthetic examples:

Thanks! Your version is indeed cleaner. I updated the patch. It uses
your version now with one group specification that I missed earlier. I
also added tests from your email, the post introducing regexp, and few
more examples I came up with.

I am testing the new regexp for a few days now. Because the regexp is
quite complex and because font-lock apparently fontifies even invisible
(folded) text, loading time on large org files with many links became
noticeably longer. Though it was 7.2Mb file with ~13k links in it.

Best,
Ihor

>From 6eb2208a67745e3150024e7b72509115b97fcfa3 Mon Sep 17 00:00:00 2001
From: Ihor Radchenko 
Date: Tue, 16 Mar 2021 20:20:32 +0800
Subject: [PATCH] Improve org-link-plain-re

(org-link-plain-re): Update docstring.  Now, the docstring explicitly
mentions that the regexp must contain groups for the link type and the
path.

* lisp/ol.el (org-link-make-regexps): Allow URLs with up to two levels
of nested brackets.  Now, URLs like [1] can be matched.  The new
regexp is based on [2].

[1] https://doi.org/10.1016/0160-791x(79)90023-x
[2] https://daringfireball.net/2010/07/improved_regex_for_matching_urls

* testing/lisp/test-ol.el: Add tests for plain links.
---
 lisp/ol.el  |  61 +--
 testing/lisp/test-ol.el | 132 
 2 files changed, 173 insertions(+), 20 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index b8bd7d234..d3a07a3ed 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -519,7 +519,10 @@ links more efficient."
   "Matches link with angular brackets, spaces are allowed.")
 
 (defvar org-link-plain-re nil
-  "Matches plain link, without spaces.")
+  "Matches plain link, without spaces.
+Group 1 must contain the link type (i.e. https).
+Group 2 must contain the link path (i.e. //example.com).
+Used by `org-element-link-parser'.")
 
 (defvar org-link-bracket-re nil
   "Matches a link in double brackets.")
@@ -807,26 +810,44 @@ This should be called after the variable `org-link-parameters' has changed."
 	  (format "<%s:\\([^>\n]*\\(?:\n[ \t]*[^> \t\n][^>\n]*\\)*\\)>"
 		  types-re)
 	  org-link-plain-re
-	  (concat
-	   "\\<" types-re ":"
-	   "\\([^][ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)")
-	  ;;	 "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
-	  org-link-bracket-re
-	  (rx (seq "[["
-		   ;; URI part: match group 1.
-		   (group
-		(one-or-more
+  (let* ((non-space-bracket "[^][ \t\n()<>]")
+	 (parenthesis
+		  `(seq "("
+		(0+ (or (regex ,non-space-bracket)
+			(seq "("
+ (0+ (regex ,non-space-bracket))
+ ")")))
+		")")))
+	;; Heuristics for an URL link inspired by
+	;; https://daringfireball.net/2010/07/improved_regex_for_matching_urls
+	(rx-to-string
+	 `(seq word-start
+   ;; Link type: match group 1.
+		   (regexp ,types-re)
+		   ":"
+   ;; Link path: match group 2.
+   (group
+		(1+ (or (regex ,non-space-bracket)
+			,parenthesis))
+		(or (regexp "[^[:punct:] \t\n]")
+		?/
+		,parenthesis)
+  org-link-bracket-re
+  (rx (seq "[["
+	   ;; URI part: match group 1.
+	   (group
+	(one-or-more
  (or (not (any "[]\\"))
-			 (and "\\" (zero-or-more "") (any "[]"))
-			 (and (one-or-more "\\") (not (any "[]"))
-		   "]"
-		   ;; Description (optional): match group 2.
-		   (opt "[" (group (+? anything)) "]")
-		   "]"))
-	  org-link-any-re
-	  (concat "\\(" org-link-bracket-re "\\)\\|\\("
-		  org-link-angle-re "\\)\\|\\("
-		  org-link-plain-re "\\)"
+		 (and "\\" (zero-or-more "") (any "[]"))
+		 (and (one-or-more "\\") (not (any "[]"))
+	   "]"
+	   ;; Description (optional): match group 2.
+	   (opt "[" (group (+? anything)) "]")
+	   "]"))
+  org-link-any-re
+  (concat "\\(" org-link-bracket-re "\\)\\|\\("
+	  org-link-angle-re "\\)\\|\\("
+	  org-link-plain-re "\\)"
 
 (defun org-link-complete-file ( arg)
   "Create a file link using completion."
diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el
index 5b7dc513b..e6208cd38 100644
--- a/testing/lisp/test-ol.el
+++ b/testing/lisp/test-ol.el
@@ -491,5 +491,137 @@
 	  (org-previous-link))
 	(buffer-substring (point) (line-end-position))
 
+
+;;; Link regexps
+
+(ert-deftest test-ol/plain-link-re ()
+  "Test `org-link-plain-re'."
+  (should
+   (equal
+'("https" "//example.com/qwe()")
+(org-test-with-temp-text
+"(Some text in parenthesis followed by link with brackets https://example.com/qwe())"
+  (list (org-element-property :type (org-element-link-parser))
+(org-element-property :path (org-element-link-parser))
+  (should
+   

Re: How to get shell source blocks to read my profile?

2021-03-16 Thread Maxim Nikulin

On 16/03/2021 00:49, George Mauer wrote:

   shell-file-name: "/bin/zsh -i"


I am afraid, you should be prepared to face some problem accidentally. 
The value of this variable is used to execute the specified file
("zsh -i" in the "/bin" directory, I do not think, you have such file), 
not as a part of shell command. shell-file-name in namely file name to 
be executed with shell-command-switch as first argument (separate 
arguments, not merged into a string) to run shell commands (next argument).


Environment variables could be set on OS level, inside emacs 
https://www.gnu.org/software/emacs/manual/html_node/emacs/Environment.html 
, etc. It is hard to suggest something since you have not described the 
problem you are trying to solve. Tim in details explained why you 
attempt to solve it did not work, but the problem (or the goal) is still 
unknown.





Re: org-capture-template: table lines including newline of sorts

2021-03-16 Thread Charles Millar

On 3/16/21 3:34 AM, Uwe Brauer wrote:


> On 3/15/21 5:00 PM, Uwe Brauer wrote:
> My bad; I did not pay attention to a four line comment, so here it is
> again, with the comment and final line for the template, etc.

> (setq org-capture-template '(

> . . . some capture templates

> ("s" "timeslip" table-line
> (file "/mnt/Data/ActiveFiles/timeslips.org")
>;;  (file "d:/ActiveFiles/timeslips.org")
>  "\| %(org-read-date)\| %^{FileName} %i\|
>  %^{Narrative} %i\| %^{Time} %i\| %^{Expense} %i"

> ;; Note that there is no escape and pipe after the final content input
>expansion
> ;; if there were a \| then an empty column is added
> ;; (org-read-date) added 2013-07-12; see Sacha Chua's use of same as in
> ;; the ledger templates below.
>  :empty-lines 1)

> , , , some more capture templates

> ))


I still obtain

| Bad template


Even copying your code without any modifications! I am running org
9.3.7

I'm running org 9.4.4 and emacs 28.0.50, (both from source) on Debian 
testing. According to my notes in my init file I created the template in 
early July 2011, modified it slightly two years later. I do not recall 
any problems with it.


Just to  make sure that there is no problem with the timeslips template, 
at least on my system, I commented out all of the capture templates 
before and after the timeslips template and reloaded my init file. I ran 
org-capture (bound to C-cm). The timeslips came up in the dispatcher and 
it ran OK.


I notice that I was off by a key and typed periods and not semicolons in 
the two lines "some capture templates," and, "some more capture templates."


Charlie Millar



Re: org-capture: question about function to create template

2021-03-16 Thread Joost Kremers
Hi Ihor & No Wayman,

Thanks for your replies.

On Tue, Mar 16 2021, Ihor Radchenko wrote:
> Joost Kremers  writes:
>
>> ... I was wondering if there's any
>> way for this function to access the state of the ongoing capture process.
>> Specifically, it would be useful for me if the function can find out the key 
>> of
>> the template that the user selected.
>
> See org-capture-plist.

Yes, I thought that might be it, but I wasn't sure.

On Mon, Mar 15 2021, No Wayman wrote:
>> From: Joost Kremers 
>> Specifically, it would be useful for me if the function can find out the key
>> of the template that the user selected.
>
> This is stored on the above plist as :key.
>
> There are some corner cases to consider if you have overlapping 
> capture processes.
> You'll want to look into `org-capture-get' and 
> `org-capture-current-plist' as well.

Thanks for the pointers. I'll dive in a little and see what's best for my use
case.



-- 
Joost Kremers
Life has its moments



Re: Sharing variables between source blocks without session

2021-03-16 Thread Loris Bennett
"Loris Bennett"  writes:

> Hi,
>
> I have a 'sh' source block which produces a table which I then want to
> plot with a 'python' source block:
>
> #+NAME: code;raw_data
> #+HEADER: :var user="loris"
>
> #+BEGIN_SRC sh
>   ps -u loris -o etimes=
> #+END_SRC

Oops, that should be 

#+NAME: code;raw_data
#+HEADER: :var user="loris"
#+BEGIN_SRC sh
  ps -u $user -o etimes=
#+END_SRC

> #+NAME: tab;raw_data
> #+RESULTS: code;raw_data...
>
> #+HEADER: :var df=tab;raw_data
> #+HEADER: :var user="loris"
>
> #+BEGIN_SRC python :results file :var f="process_times.pdf"
>   import numpy as np
>   import matplotlib.pyplot as plt
>   # flatten list
>   x = [item for sublist in df for item in sublist]
>   plt.hist(x, bins=10)
>   plt.xlabel("time [s]")
>   plt.ylabel("number of processes")
>   plt.title("user: " + user)
>   plt.savefig(f) 
>   return f
> #+END_SRC
>
> How can I avoid having to declare the variable 'user' for both blocks?
>
> Cheers,
>
> Loris
-- 
Dr. Loris Bennett (Hr./Mr.)
ZEDAT, Freie Universität Berlin Email loris.benn...@fu-berlin.de




Sharing variables between source blocks without session

2021-03-16 Thread Loris Bennett
Hi,

I have a 'sh' source block which produces a table which I then want to
plot with a 'python' source block:

#+NAME: code;raw_data
#+HEADER: :var user="loris"
#+BEGIN_SRC sh
  ps -u loris -o etimes=
#+END_SRC   

 

#+NAME: tab;raw_data
#+RESULTS: code;raw_data...

#+HEADER: :var df=tab;raw_data
#+HEADER: :var user="loris"
#+BEGIN_SRC python :results file :var f="process_times.pdf"
  import numpy as np
  import matplotlib.pyplot as plt
  # flatten list
  x = [item for sublist in df for item in sublist]
  plt.hist(x, bins=10)
  plt.xlabel("time [s]")
  plt.ylabel("number of processes")
  plt.title("user: " + user)
  plt.savefig(f) 
  return f
#+END_SRC

How can I avoid having to declare the variable 'user' for both blocks?

Cheers,

Loris

-- 
This signature is currently under construction.



Re: org-capture-template: table lines including newline of sorts

2021-03-16 Thread Uwe Brauer

   > On 3/15/21 5:00 PM, Uwe Brauer wrote:
   > My bad; I did not pay attention to a four line comment, so here it is
   > again, with the comment and final line for the template, etc.

   > (setq org-capture-template '(

   > . . . some capture templates

   > ("s" "timeslip" table-line
   > (file "/mnt/Data/ActiveFiles/timeslips.org")
   >;;  (file "d:/ActiveFiles/timeslips.org")
   >  "\| %(org-read-date)\| %^{FileName} %i\|
   >  %^{Narrative} %i\| %^{Time} %i\| %^{Expense} %i"

   > ;; Note that there is no escape and pipe after the final content input
   >expansion
   > ;; if there were a \| then an empty column is added
   > ;; (org-read-date) added 2013-07-12; see Sacha Chua's use of same as in
   > ;; the ledger templates below.
   >  :empty-lines 1)

   > , , , some more capture templates

   > ))


I still obtain 

| Bad template 


Even copying your code without any modifications! I am running org
9.3.7


smime.p7s
Description: S/MIME cryptographic signature


SOLVED: Problems while trying to load feature

2021-03-16 Thread Ypo

Thanks, Nick. SOLVED :-)

El 15/03/2021 a las 17:00, emacs-orgmode-requ...@gnu.org escribió:

Message: 30
Date: Mon, 15 Mar 2021 11:15:29 -0400
From: Nick Dokos
To:emacs-orgmode@gnu.org
Subject: Re: Problems while trying to load feature
Message-ID:<878s6o8n3i@alphaville.usersys.redhat.com>
Content-Type: text/plain

The renaming was e.g org-bbdb to ol-bbdb,*NOT*  to ol-org-bbdb.

Similarly for all the rest: you won't find any of them in any installation.

-- Nick