Re: [O] Bug: org-paste-subtree may delete headline at point [9.1.14 (release_9.1.14-961-g5abfde)]

2018-10-04 Thread Nicolas Goaziou
Hello,

Dale Sedivec  writes:

> Hi, I think I may have found a bug in org-paste-subtree in master branch
> where it will delete the content of the headline at point before yanking.
> Steps to reproduce:
>
> 1. Start a fresh Emacs along the lines of:
>
> mkdir /tmp/fake-home
> cd /tmp/fake-home
> git clone https://code.orgmode.org/bzg/org-mode.git
> (cd org-mode && make autoloads)
> HOME=/tmp/fake-home emacs -L /tmp/fake-home/org-mode/lisp
>
> 2. Create a new org file with the following contents:
>
> * One
> * Two
> * Three
>
> 3. Move point to the "Two" headline, use C-c C-x C-w to kill it
>
> 4. Move point to *the end* of the "One" headline (first line)
>
> 5. Try to yank the "Two" headline: C-c C-x C-y (org-paste-special ->
> org-paste-subtree)
>
> Expected results (using ~~ as delimiters here):
>
> ~~
> * One
> * Two
> * Three
> ~~
>
> Observed results:
>
> ~~
>
> * Two
> * Three
> ~~
>
> Note that all content on the "* One" line where we invoked
> org-paste-subtree has been deleted.

Ouch. Thank you for spotting this and for the analysis. I applied
a patch in the line of what you suggested.

Regards,

-- 
Nicolas Goaziou



[O] Bug: org-paste-subtree may delete headline at point [9.1.14 (release_9.1.14-961-g5abfde)]

2018-10-04 Thread Dale Sedivec
Hi, I think I may have found a bug in org-paste-subtree in master branch
where it will delete the content of the headline at point before yanking.
Steps to reproduce:

1. Start a fresh Emacs along the lines of:

mkdir /tmp/fake-home
cd /tmp/fake-home
git clone https://code.orgmode.org/bzg/org-mode.git
(cd org-mode && make autoloads)
HOME=/tmp/fake-home emacs -L /tmp/fake-home/org-mode/lisp

2. Create a new org file with the following contents:

* One
* Two
* Three

3. Move point to the "Two" headline, use C-c C-x C-w to kill it

4. Move point to *the end* of the "One" headline (first line)

5. Try to yank the "Two" headline: C-c C-x C-y (org-paste-special ->
org-paste-subtree)

Expected results (using ~~ as delimiters here):

~~
* One
* Two
* Three
~~

Observed results:

~~

* Two
* Three
~~

Note that all content on the "* One" line where we invoked
org-paste-subtree has been deleted.

I suspect the problem may be in org-paste-subtree.  Here's an excerpt that
calculates the value for force-level:

~~
  (force-level
   (cond
(level (prefix-numeric-value level))
;; When point is right after the stars in an otherwise
;; empty headline, use stars as the forced level.
((and (looking-at-p "[ \t]*$")
  (string-match-p "^\\*+ *"
  (buffer-substring (line-beginning-position)
(point
 (org-outline-level))
((looking-at-p org-outline-regexp-bol) (org-outline-level
~~

The comment says it's trying to identify an "empty headline", but the
combination of the two regexes there seems to simply confirm that point is
at EOL, ignoring white space, and that we're on a headline.  They seem to
do nothing to ensure that there is no content between the headline bullets
and EOL, so force-level becomes non-nil, which causes org-paste-subtree to
delete the contents of the line at point.

Assuming the comment's intent is correct, perhaps the
looking-at-p/string-match-p pair should just be replaced with something
like this?

(string-match-p "^\\*+\\s-*$" (buffer-substring (line-beginning-position)
(point)))

Version info:

Emacs  : GNU Emacs 26.1.50 (build 2, x86_64-apple-darwin17.7.0, NS
appkit-1561.60 Version 10.13.6 (Build 17G65))
 of 2018-08-31
Package: Org mode version 9.1.14 (release_9.1.14-961-g5abfde @
/tmp/orgbug/org-mode/lisp/)

Regards,
Dale


Re: [O] Calculate differences of remote table numbers

2018-10-04 Thread Nick Dokos
Karl Voit  writes:

>>
>> @# is the row number, so to refer to that row, you need @@#. Something like 
>> this,
>> although I didn't test to see if everything gets parsed correctly:
>>
>> #+TBLFM: $2=if(2 == @#, 0, remote(my-table,@@#$1))::$3=if(2 == @#,
>> 0, remote(my-table,@@#-1$1))::$4=if(2 == @#, 0,
>> (remote(my-table,@@#$1)-remote(my-table,@@#-1$1)))
>
> This is a huge step forward:
>
> #+NAME: my-table
> | Numbers |
>
> |-|
> |   1 |
> |   5 |
> |   8 |
> |  12 |
> |  15 |
>
> | Line | exp. Reference1 | exp. Reference2 | exp. Difference |
> |--+-+-+-|
> |1 |   0 |   0 |   0 |
> |2 |   5 |   1 |   4 |
> |3 |   8 |   5 |   3 |
> |4 |  12 |   8 |   4 |
> |5 |  15 |  12 |   3 |
>
>
> | Line | actual Reference1 | actual Reference2 | Difference |
> |--+---+---+|
> |1 | 0 | 0 |  0 |
> |2 | 5 | 5 |  0 |
> |3 | 8 | 8 |  0 |
> |4 |12 |12 |  0 |
> |5 |15 |15 |  0 |
>
> #+TBLFM: $2=if(2 == @#, 0, remote(my-table,@@#$1))::$3=if(2 == @#, 0, 
> remote(my-table,@@#-1$1))::$4=if(2 == @#, 0, 
> (remote(my-table,@@#$1)-remote(my-table,@@#-1$1)))
>
> Somehow, the "-1" in "@@#-1$1" does not have any effect: "@@#$1" and
> "@@#-1$" gives the same results.
>
> Do you have any idea why?

Yes, that's what I was afraid of when I said "...if everything is parsed 
correctly".
AFAICT, you cannot use expressions (I tried parentheses and curly braces as 
well: the
formula debugger complains that it expected a number.

One workaround is to add a column to the original table where you *can* 
calculate
using row/column expressions and then use each column where appropriate in the
remote references. Something like this:

--8<---cut here---start->8---
#+NAME: my-table
| Numbers | shifted |
|-+-|
|   1 |   0 |
|   5 |   1 |
|   8 |   5 |
|  12 |   8 |
|  15 |  12 |
#+TBLFM: @2$2..@>$2 = if(2==@#, 0, @-1$1)

| Line | exp. Reference1 | exp. Reference2 | exp. Difference |
|--+-+-+-|
|1 |   0 |   0 |   0 |
|2 |   5 |   1 |   4 |
|3 |   8 |   5 |   3 |
|4 |  12 |   8 |   4 |
|5 |  15 |  12 |   3 |

| Line | actual Reference1 | actual Reference2 | Difference |
|--+---+---+|
|1 | 0 | 0 |  0 |
|2 | 5 | 1 |  4 |
|3 | 8 | 5 |  3 |
|4 |12 | 8 |  4 |
|5 |15 |12 |  3 |
#+TBLFM: $2=if(2 == @#, 0, remote(my-table,@@#$1))::$3=if(2 == @#, 0, 
remote(my-table,@@#$2))::$4=$2-$3
--8<---cut here---end--->8---

But somebody (perhaps Michael Brand, if he is around) might come up
with better ideas.

>
>> Turning on formula debugging with `C-c {' helps.
>
> Woha! I didn't know that! And I also didn't know =C-c }= for
> displaying column/row numbers :-O *This* is going to be handy for me
> ;-)

Both Emacs and Org Mode are unending sources of new discovery and
delight!-)

-- 
Nick

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




Re: [O] org-babel-detangle issue on 9.1.14

2018-10-04 Thread Brad Knotwell
 Thanks for the response.  At a minimum, I'd recommend changing the error 
message from "Not in a source block" to something more descriptive as most 
people's initial response will be, "uhhh, but it looks like I am."  
Ideally, an additional comment marker would delineate the source block from the 
meta-programmed variables to allow the edited source code's verbatim 
replacement.  Or it might make sense to have a setting that separates the 
tangled source file from the meta programmed variables.  Using your example 
above, it could tangle to something like the following:
#!/bin/sh
# 
[[file:~/tmp/test.org::org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE][org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE]].
 ./noideahowtonamethesegenerically.sh    # the naming seems tricky to me
echo $x# 
org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE
ends here
If babel was starting anew, I'd prefer that as it seems cleaner than adding 
another comment (assumption: majority of languages have an include-like 
facility of some sort).  Given the number of languages currently supported, the 
additional comment delimiters seem less disruptive.

--Brad
On Thursday, October 4, 2018, 8:19:30 AM PDT, Grant Rettke 
 wrote:  
 
 On Thu, Oct 4, 2018 at 2:09 AM Brad Knotwell  wrote:
> I've been playing with org-babel-detangle and I've noticed something that's 
> either a bug or a limitation.  It's confusing enough that
> it's worth writing down if it's expected.  Basically, it doesn't work if 
> there are variables defined in the begin_src header.  I've
> attached an example below.  The first one won't detangle and the last two 
> will.

That is expected behavior. Org can only detangle the content of source
blocks. It can't deduce how that
source code got in there.

Maybe this example says it better:

#+begin_src sh sh :tangle hw.sh :var x=(random) :shebang #!/bin/sh
:comments link
echo $x
#+end_src

Tangles to

#!/bin/sh
# 
[[file:~/tmp/test.org::org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE][org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE]]
x='422131055910453451'
echo $x
# 
org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE
ends here
  

Re: [O] org-babel-detangle issue on 9.1.14

2018-10-04 Thread Grant Rettke
On Thu, Oct 4, 2018 at 2:09 AM Brad Knotwell  wrote:
> I've been playing with org-babel-detangle and I've noticed something that's 
> either a bug or a limitation.  It's confusing enough that
> it's worth writing down if it's expected.  Basically, it doesn't work if 
> there are variables defined in the begin_src header.  I've
> attached an example below.  The first one won't detangle and the last two 
> will.

That is expected behavior. Org can only detangle the content of source
blocks. It can't deduce how that
source code got in there.

Maybe this example says it better:

#+begin_src sh sh :tangle hw.sh :var x=(random) :shebang #!/bin/sh
:comments link
echo $x
#+end_src

Tangles to

#!/bin/sh
# 
[[file:~/tmp/test.org::org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE][org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE]]
x='422131055910453451'
echo $x
# 
org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE
ends here



[O] [RFC] Replace lambda functions added to org-mode-hook with named funcs

2018-10-04 Thread Kaushal Modi
Hello,

Yesterday, while helping someone out[0] with why their custom
functions added to org-mode-hook didn't work, I asked them to reveal
the value of org-mode-hook, and they presented this as the default
value of org-mode-hook once Org was loaded:

=
'(org-mode-hook
   (quote
(#[0 "\300\301\302\303\304$\207"
 [add-hook change-major-mode-hook org-show-block-all append local]
 5]
 #[0 "\300\301\302\303\304$\207"
 [add-hook change-major-mode-hook org-babel-show-result-all
append local]
 5]
 org-babel-result-hide-spec org-babel-hide-all-hashes)))
=

Going down the rabbit hole, I discovered many places in Org source
where lambdas were added to org-mode-hook.

I propose to replace such lamba functions with named functions.
Here's an example of diff on maint branch, after making one such change:

=
diff --git a/lisp/org.el b/lisp/org.el
index 2cc9b6a1c..9f28502d4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7429,10 +7429,10 @@ a block.  Return a non-nil value when toggling
is successful."
   (when (eq (overlay-get ov 'invisible) 'org-hide-block)
 (delete-overlay ov

-;; Remove overlays when changing major mode
-(add-hook 'org-mode-hook
-  (lambda () (add-hook 'change-major-mode-hook
-   'org-show-block-all 'append 'local)))
+(defun org--unfold-all-blocks-on-major-mode-change ()
+  "Remove overlays when changing major mode."
+  (add-hook 'change-major-mode-hook #'org-show-block-all 'append 'local))
+(add-hook 'org-mode-hook #'org--unfold-all-blocks-on-major-mode-change)

 ;;; Org-goto
 =

If there is no objection to this, I can fix this everywhere in maint,
and then merge that into master.

Comments?


--
Kaushal Modi

[0]: 
https://www.reddit.com/r/emacs/comments/9l1aji/org_mode_hooks_dont_work/e73awsc/



Re: [O] org-babel: capturing the output of a shell command that does not return

2018-10-04 Thread Grant Rettke
On Wed, Sep 19, 2018 at 3:35 PM  wrote:
> Maybe there is another way to run the shell command and extract the file name 
> I need (in elisp?), but I don't know how.

What if you start Emacs, have it create a temp file, then in a
separate terminal start Jupyter with stdout redirected to that file.

Is that in the right direction of what you are describing?



Re: [O] Section on #+include keyword is missing quite some info in the org-manual.org

2018-10-04 Thread Kaushal Modi
On Mon, Oct 1, 2018 at 3:25 PM Kaushal Modi  wrote:

> I was thinking of adding cindices like the ones you added for header
> arguments.
>
> #+cindex: @samp{minlevel}, include
> #+cindex: @samp{lines}, include
> .. etc.
>
> Would that be OK?
>

I went ahead as this wasn't a major edit, and committed this in
https://code.orgmode.org/bzg/org-mode/commit/5abfdeeb8f72dfc2db324e8e731f4e16f2b54bea
.


[O] blogging with lazyblorg (was: Visualizing org files)

2018-10-04 Thread Karl Voit
* Marcelo de Moraes Serpa  wrote:
>
> Oh wow Karl, lot's of 'hidden' gems there. 

Thanks. Glad that you like it. Consider following Atom/RSS feeds of
https://karl-voit.at/ to get updates on my PIM/Emacs activity. I
hope that I'm going to implement tag-specific feeds so that you are
able to follow #pim or #emacs and don't get any non-related updates.

> Not related to this thread but I specially liked `lazyblorg`, I
> actually had a very similar idea and was about to develop
> something like that, you saved me a bunch of time :)

Oh, it took quite some effort and time to go where lazyblorg
currently is ;-) Feedback welcome.

-- 
get mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML into Org-mode:
   > get Memacs from https://github.com/novoid/Memacs <
Personal Information Management > http://Karl-Voit.at/tags/pim/
Emacs-related > http://Karl-Voit.at/tags/emacs/




Re: [O] Calculate differences of remote table numbers

2018-10-04 Thread Karl Voit
Hi Nick,

* Nick Dokos  wrote:
> Karl Voit  writes:
>
>> I'd like to calculate the differences between rows of numbers of a
>> different table.
>>
>> Here is a minimal example showing the issue:
>>
>> #+NAME: my-table
>> | Numbers |
>>
>> |-|
>> |   1 |
>> |   5 |
>> |   8 |
>> |  12 |
>> |  15 |
>>
>> This is what I expected: "exp. Reference1" and "exp. Reference2" is here only
>> to demonstrate that the assumed references are wrong in the third table. 
>> "exp.
>> Difference" is the column I want to get in the first place. I don't want to 
>> see
>> Reference 1 or 2 at all in my solution (since I need a couple of those
>> difference-columns).
>>
>> | Line | exp. Reference1 | exp. Reference2 | exp. Difference |
>> |--+-+-+-|
>> |1 |   0 |   0 |   0 |
>> |2 |   5 |   1 |   4 |
>> |3 |   8 |   5 |   3 |
>> |4 |  12 |   8 |   4 |
>> |5 |  15 |  12 |   3 |
>>
>> This is what I get instead:
>>
>> | Line | actual Reference1 | actual Reference2 | Difference |
>> |--+---+---+|
>> |1 | 0 | 0 |  0 |
>> |2 | 6 | 1 |  5 |
>> |3 |12 | 1 | 11 |
>> |4 |20 | 1 | 19 |
>> |5 |30 | 1 | 29 |
>
> @# is the row number, so to refer to that row, you need @@#. Something like 
> this,
> although I didn't test to see if everything gets parsed correctly:
>
> #+TBLFM: $2=if(2 == @#, 0, remote(my-table,@@#$1))::$3=if(2 == @#, 0, 
> remote(my-table,@@#-1$1))::$4=if(2 == @#, 0, 
> (remote(my-table,@@#$1)-remote(my-table,@@#-1$1)))

This is a huge step forward:

#+NAME: my-table
| Numbers |
|-|
|   1 |
|   5 |
|   8 |
|  12 |
|  15 |

| Line | exp. Reference1 | exp. Reference2 | exp. Difference |
|--+-+-+-|
|1 |   0 |   0 |   0 |
|2 |   5 |   1 |   4 |
|3 |   8 |   5 |   3 |
|4 |  12 |   8 |   4 |
|5 |  15 |  12 |   3 |


| Line | actual Reference1 | actual Reference2 | Difference |
|--+---+---+|
|1 | 0 | 0 |  0 |
|2 | 5 | 5 |  0 |
|3 | 8 | 8 |  0 |
|4 |12 |12 |  0 |
|5 |15 |15 |  0 |
#+TBLFM: $2=if(2 == @#, 0, remote(my-table,@@#$1))::$3=if(2 == @#, 0, 
remote(my-table,@@#-1$1))::$4=if(2 == @#, 0, 
(remote(my-table,@@#$1)-remote(my-table,@@#-1$1)))

Somehow, the "-1" in "@@#-1$1" does not have any effect: "@@#$1" and
"@@#-1$" gives the same results.

Do you have any idea why?

> Turning on formula debugging with `C-c {' helps.

Woha! I didn't know that! And I also didn't know =C-c }= for
displaying column/row numbers :-O *This* is going to be handy for me
;-)

-- 
get mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML into Org-mode:
   > get Memacs from https://github.com/novoid/Memacs <
Personal Information Management > http://Karl-Voit.at/tags/pim/
Emacs-related > http://Karl-Voit.at/tags/emacs/