[O] [PATCH] Fix other commands for exiting narrowing (2)

2019-02-17 Thread Leo Vivier


* lisp/org.el (org-toggle-narrow-to-subtree): Different interactive
  calls and use wrapper for widen
---
Same deal as the last email.  Sorry for only noticing those commands
now; I don't use them in my workflow.

The change in `interactive' is to ensure that only the interactive calls
to `org-narrow-to-subtree' produce the last newline.

 lisp/org.el | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 292807138..ef86423e8 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8421,12 +8421,12 @@ end of the narrowed tree."
  (when newline (insert "\n")))
   (point)))
 
-(defun org-toggle-narrow-to-subtree ()
+(defun org-toggle-narrow-to-subtree ( newline)
   "Narrow to the subtree at point or widen a narrowed buffer."
-  (interactive)
+  (interactive "p")
   (if (buffer-narrowed-p)
-  (widen)
-(org-narrow-to-subtree)))
+  (org-widen)
+(org-narrow-to-subtree newline)))
 
 (defun org-narrow-to-block ()
   "Narrow buffer to the current block."
-- 
2.20.1




[O] [PATCH] Fix other commands for exiting narrowing

2019-02-17 Thread Leo Vivier


* lisp/org.el (org-kill-buffer): Create a wrapper for kill-buffer to
  handle last newline deletion.
  (org-kill-buffer-and-window): Create a wrapper for
  kill-buffer-and-window to handle last newline deletion.

* lisp/org-keys.el (org-remap): Remap kill-buffer and
  kill-buffer-and-window to org wrappers.
---
I'd forgotten to patch the commands for exiting indirect buffers
spawned by `org-tree-to-indirect-buffer'.

This needs to be squashed with the first commit.

Sorry for the bother.
  
 lisp/org-keys.el |  2 ++
 lisp/org.el  | 21 +
 2 files changed, 23 insertions(+)

diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index 26a3852b3..0f4fd5b6d 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -533,6 +533,8 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command 
names."
   'delete-backward-char   'org-delete-backward-char
   'kill-line  'org-kill-line
   'kill-region'org-kill-region
+  'kill-buffer'org-kill-bufer
+  'kill-buffer-and-window 'org-kill-buffer-and-window
   'widen  'org-widen
   'open-line  'org-open-line
   'yank   'org-yank
diff --git a/lisp/org.el b/lisp/org.el
index 02130ab6a..292807138 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7442,6 +7442,27 @@ frame is not changed."
 (make-indirect-buffer buffer bname 'clone)
   (error (make-indirect-buffer buffer bname)
 
+(defun org-kill-buffer ( buffer-or-name)
+  "Kill the buffer specified by BUFFER-OR-NAME.
+The argument may be a buffer or the name of an existing buffer.
+Argument nil or omitted means kill the current buffer.  Return t if the
+buffer is actually killed, nil otherwise.
+
+Wrapper for org.  See `kill-buffer' for more info."
+  (interactive)
+  (when (buffer-base-buffer)
+(org-widen))
+  (kill-buffer buffer-or-name))
+
+(defun org-kill-buffer-and-window ()
+  "Kill the current buffer and delete the selected window.
+
+Wrapper for org.  See `kill-buffer-and-window' for more info."
+  (interactive)
+  (when (buffer-base-buffer)
+(org-widen))
+  (kill-buffer-and-window))
+
 (defun org-set-frame-title (title)
   "Set the title of the current frame to the string TITLE."
   (modify-frame-parameters (selected-frame) (list (cons 'name title
-- 
2.20.1




[O] [PATCH 1/2] Fix narrowing for 1-line subtrees

2019-02-17 Thread Leo Vivier
* lisp/org.el (org-narrow-to-subtree): Ensure newline at end of
  subtree.
  (org-tree-to-indirect-buffer): Ensure newline at end of
  subtree.
  (org-widen): Create wrapper for `widen' to handle end newline.

* lisp/org-capture.el (org-capture-finalize): Replace `widen' with
  `org-widen'.
  (org-capture-narrow): Ensure newline at end of subtree.

* lisp/org-keys.el (org-remap): Remap `widen' to `org-widen'.

There was a problem with narrowed 1-line subtrees which caused
clocking and scheduling commands to print their modifications outside
of the current narrowing, e.g. `org-clock-in'. This also prevented
some commands from working as expected,
e.g. `org-clock-out-when-done', since the clock-drawer isn't visible.

Previous commits have addressed this problem by patching those
commands to act on a widened buffer within a `save-restriction'
environment (cf. 8fc22d464, 503ede74b, and 6872088c7) but this does
not address the original problem, namely the modifications not being
visible in the narrowed buffer.

The problem is inherent to Emacs's narrowing.  In org-mode, the
narrowing commands use `org-end-of-subtree' to retrieve the
end-position of the region to be narrowed.  However, with a 1-line
subtree, `org-end-of-subtree' moves the point to the end of the line
which is before the position where clocking and scheduling commands
print their modifications, i.e. right below the headline.

To address the problem, we need to change the way we narrow and widen
buffers in org-mode:
- We patch the narrowing commands in org-mode to always add a newline
  at the end of subtrees (not only the 1-line subtrees).  This ensures
  that clocking and scheduling commands print their modifications
  within the narrowed buffer.
- We create a wrapper for `widen' within org-mode (called `org-widen')
  which deletes the newline added when we narrowed the buffer to the
  subtree.

However, for this solution to be complete, we need to ensure that the
newlines added by the narrowing commands cannot be deleted by the
user.
---
This is an implementation of the solution I've discussed in 'Bug:
org-clock commands spawn drawer outside of narrowing' on Fri, 15 Feb
2019 09:48:00 +0100.

I've tried it with `emacs -q' and with different numbers of
blank-lines between headings, and  I haven't encountered any problem so
far.  The code doesn't make any assumption about how many lines you
should have between your headings, which means that it shouldn't
interfere with `org-blank-before-new-entry'.

If there are more idiomatic ways to write some of the functions,
please let me know.

Thank you.

 lisp/org-capture.el | 12 +---
 lisp/org-keys.el|  1 +
 lisp/org.el | 26 +-
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index debf1808c..ff3134fb4 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -746,7 +746,7 @@ captured item after finalizing."
   (let ((abort-note nil))
 ;; Store the size of the capture buffer
 (org-capture-put :captured-entry-size (- (point-max) (point-min)))
-(widen)
+(org-widen)
 ;; Store the insertion point in the target buffer
 (org-capture-put :insertion-point (point))
 
@@ -1416,8 +1416,14 @@ Of course, if exact position has been required, just put 
it there."
 (defun org-capture-narrow (beg end)
   "Narrow, unless configuration says not to narrow."
   (unless (org-capture-get :unnarrowed)
-(narrow-to-region beg end)
-(goto-char beg)))
+(goto-char beg)
+(narrow-to-region
+ beg
+ (progn (org-end-of-subtree t t)
+(when (and (org-at-heading-p) (not (eobp)))
+  (backward-char 1)
+  (insert "\n"))
+(point)
 
 (defun org-capture-empty-lines-before ( n)
   "Set the correct number of empty lines before the insertion point.
diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index d103957a9..90e8139b0 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -532,6 +532,7 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command 
names."
   'delete-char'org-delete-char
   'delete-backward-char   'org-delete-backward-char
   'kill-line  'org-kill-line
+  'widen  'org-widen
   'open-line  'org-open-line
   'yank   'org-yank
   'comment-dwim   'org-comment-dwim
diff --git a/lisp/org.el b/lisp/org.el
index ebec2befa..3110f14ba 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7391,7 +7391,9 @@ frame is not changed."
   (setq beg (point)
heading (org-get-heading 'no-tags))
   (org-end-of-subtree t t)
-  (when (org-at-heading-p) (backward-char 1))
+  (when (and (org-at-heading-p) (not (eobp)))
+  (backward-char 1)
+  (insert "\n"))
   (setq end (point)))
 (when (and (buffer-live-p org-last-indirect-buffer)
   (not (eq 

[O] [PATCH 2/2] Prevent deletion of newline added by narrowing

2019-02-17 Thread Leo Vivier
* lisp/org.el (org-delete-backward-char): Prevent deletion of newline
  added by narrowing
  (org-delete-char): Prevent deletion of newline added by narrowing
  (org-kill-line): Prevent deletion of newline added by narrowing
  (org-kill-region): Create wrapper for `kill-region' to prevent
  deletion of newline added by narrowing

* lisp/org-keys.el (org-remap): Remap `kill-region' to
  `org-kill-region'

This ensures that the newline added by the narrowing commands cannot
be deleted by the user.

It does so by having every interactive deletion command check whether
it would delete the last newline of a narrowed buffer.  If it would,
the new command deletes whatever the original command normally would
but keep the last newline.  If the original command would have
resulted in a movement, e.g. `org-delete-backward-char', the new
command also moves the point as if the last newline had been deleted.
---
 lisp/org-keys.el |  1 +
 lisp/org.el  | 28 
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index 90e8139b0..26a3852b3 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -532,6 +532,7 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command 
names."
   'delete-char'org-delete-char
   'delete-backward-char   'org-delete-backward-char
   'kill-line  'org-kill-line
+  'kill-region'org-kill-region
   'widen  'org-widen
   'open-line  'org-open-line
   'yank   'org-yank
diff --git a/lisp/org.el b/lisp/org.el
index 3110f14ba..02130ab6a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18851,7 +18851,11 @@ because, in this case the deletion might narrow the 
column."
 (looking-at-p ".*?|")
 (org-at-table-p))
(progn (forward-char -1) (org-delete-char 1))
-  (backward-delete-char N)
+  (if (and (eobp)
+   (save-excursion (forward-char -1)
+   (looking-at "\n")))
+  (forward-char -1)
+(backward-delete-char N))
   (org-fix-tags-on-the-fly
 
 (defun org-delete-char (N)
@@ -18868,7 +18872,9 @@ because, in this case the deletion might narrow the 
column."
  (eq (char-after) ?|)
  (save-excursion (skip-chars-backward " \t") (bolp))
  (not (org-at-table-p)))
-  (delete-char N)
+  (unless (and (save-excursion (forward-char) (eobp))
+(looking-at "\n"))
+ (delete-char N))
   (org-fix-tags-on-the-fly))
  ((looking-at ".\\(.*?\\)|")
   (let* ((update? org-table-may-need-update)
@@ -22301,8 +22307,12 @@ depending on context."
   (user-error
(substitute-command-keys
"`\\[org-kill-line]' aborted as it would kill a hidden subtree")))
-(call-interactively
- (if (bound-and-true-p visual-line-mode) 'kill-visual-line 'kill-line)))
+(unless (and (looking-at-p "\n")
+(save-excursion
+  (forward-char 1)
+  (eobp)))
+  (call-interactively
+   (if (bound-and-true-p visual-line-mode) 'kill-visual-line 'kill-line
((org-match-line org-tag-line-re)
 (let ((end (save-excursion
 (goto-char (match-beginning 1))
@@ -22314,6 +22324,16 @@ depending on context."
 (org-align-tags))
(t (kill-region (point) (line-end-position)
 
+(defun org-kill-region (beg end  region)
+  (interactive (list (mark) (point) 'region))
+  (kill-region
+   beg
+   end
+   region)
+  (save-excursion
+(when (eobp)
+   (insert "\n"
+
 (defun org-yank ( arg)
   "Yank.  If the kill is a subtree, treat it specially.
 This command will look at the current kill and check if is a single
-- 
2.20.1




[O] Bug: org-show-all is missing an (interactive) declaration [9.2.1 (9.2.1-elpa @ /Users/piet/.emacs.d/elpa/org-9.2.1/)]

2019-02-17 Thread Piet van Oostrum


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


In org-mode 9.2.1, the menu item Org > Show/Hide > Show All is bound to 
org-show-all, but this function is nor=t interactive. Therefore the invocation 
of this menu item fails.

command-execute: Wrong type argument: commandp, org-show-all

Solution: add (interactive)

diff -u /Users/piet/.emacs.d/elpa/org-9.2.1/org.el.\~1\~ 
/Users/piet/.emacs.d/elpa/org-9.2.1/org.el
--- /Users/piet/.emacs.d/elpa/org-9.2.1/org.el.~1~  2019-02-17 
21:37:16.0 +0100
+++ /Users/piet/.emacs.d/elpa/org-9.2.1/org.el  2019-02-17 21:54:11.0 
+0100
@@ -6935,6 +6935,7 @@
 By default, the function expands headings, blocks and drawers.
 When optional argument TYPE is a list of symbols among `blocks',
 `drawers' and `headings', to only expand one specific type."
+  (interactive)
   (dolist (type (or types '(blocks drawers headings)))
 (org-flag-region (point-min) (point-max) nil
 (pcase type




Emacs  : GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS appkit-1348.17 
Version 10.10.5 (Build 14F2511))
 of 2018-05-31
Package: Org mode version 9.2.1 (9.2.1-elpa @ 
/Users/piet/.emacs.d/elpa/org-9.2.1/)

current state:
==
(setq
 org-src-mode-hook '(org-src-babel-configure-edit-buffer 
org-src-mode-configure-edit-buffer)
 org-after-todo-state-change-hook '(org-clock-out-if-current)
 org-calendar-to-agenda-key [99]
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 org-html-format-inlinetask-function 
'org-html-format-inlinetask-default-function
 org-odt-format-headline-function 'org-odt-format-headline-default-function
 org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default
 org-reveal-start-hook '(org-decrypt-entry)
 org-modules '(org-w3m org-bbdb org-bibtex org-docview org-gnus org-info 
org-irc org-mhe org-rmail)
 org-export-creator-string "Emacs 26.1 (Org mode 9.1.9)"
 org-mime-library 'vm
 org-mode-hook '(#[0 "\300\301\302\303\304$\207"
   [add-hook change-major-mode-hook 
org-show-all append local] 5]
 #[0 "\301\211\207" 
[imenu-create-index-function org-imenu-get-tree] 2]
 #[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)
 org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-confirm-elisp-link-function 'yes-or-no-p
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn 
ENTRY)"]
 org-latex-format-drawer-function #[514 "\207" [] 3 "\n\n(fn _ CONTENTS)"]
 org-agenda-deadline-faces '((1.0 . org-warning) (0.5 . org-upcoming-deadline) 
(0.0 . default))
 org-babel-pre-tangle-hook '(save-buffer)
 org-tab-first-hook '(org-babel-hide-result-toggle-maybe 
org-babel-header-arg-expand)
 org-html-creator-string "https://www.gnu.org/software/emacs/\;>Emacs 26.1 (https://orgmode.org\;>Org mode 9.1.9)"
 org-ascii-format-drawer-function #[771 "\207" [] 4 "\n\n(fn NAME CONTENTS 
WIDTH)"]
 org-src-lang-modes '(("ocaml" . tuareg) ("elisp" . emacs-lisp) ("ditaa" . 
artist)
  ("asymptote" . asy) ("dot" . 
fundamental) ("sqlite" . sql)
  ("calc" . fundamental) ("C" . c) 
("cpp" . c++) ("C++" . c++)
  ("screen" . shell-script) ("shell" . 
sh) ("bash" . sh))
 org-latex-table-scientific-notation "%s\\,(%s)"
 org-html-infojs-template "\n/**\n *\n * @source: %SCRIPT_PATH\n *\n * @licstart  The 
following is the entire license notice for the\n *  JavaScript code in 
%SCRIPT_PATH.\n *\n * Copyright (C) 2012-2018 Free Software Foundation, Inc.\n 
*\n *\n * The JavaScript code in this tag is free software: you can\n * 
redistribute it and/or modify it under the terms of the GNU\n * General Public 
License (GNU GPL) as published by the Free Software\n * Foundation, either 
version 3 of the License, or (at your option)\n * any later version.  The code 
is distributed WITHOUT ANY WARRANTY;\n * without even the implied warranty of 
MERCHANTABILITY or FITNESS\n * FOR A PARTICULAR PURPOSE.  See the GNU GPL for 
more details.\n *\n * 

Re: [O] Bug: Org 9.2.1 table issues [9.2.1 (9.2.1-dist @ /Users/nick/.emacs.d/lisp/org-9.2.1/)]

2019-02-17 Thread Nicolas Goaziou
Hello,

Nick Helm  writes:

> If that's the case, it's a significant loss of functionality. This would
> mean, for instance, that it's no longer possible to format financial
> data with a uniform column width.

"significant" may be relative. The feature has been available on master
for months, and this went unnoticed.

Anyway, I changed the algorithm, so shrinking should now obey to
alignment. Thank you for the feedback.

> Let me try to illustrate with another example. If you shrink this table
> with C-c TAB:
>
> | <5>  |
> | one  two |
> | one  |
>
> you get the following:
>
> | <5> …|
> | one …|
> | one …|
>
> This is misleading - cell 3 contains no additional content yet the
> indicator says it does. It's also ambiguous - it's impossible to
> determine whether cell 2 or 3 contains the longer field.
>
> Compare with this, where such information is clearly conveyed:
>
> | <5>  |
> | one …|
> | one  |

This is not misleading. The "…" characters means the /column/ as a whole
is shrunk, not that an individual field is. Luckily, you can easily use,
for example, `C-TAB` for the rare case the situation requires
disambiguation.

> Has this been removed from 9.2 as well?

Yes, it has.

Regards,

-- 
Nicolas Goaziou