diff options
author | Carsten Dominik <carsten.dominik@gmail.com> | 2010-06-02 20:20:10 +0200 |
---|---|---|
committer | Carsten Dominik <carsten.dominik@gmail.com> | 2010-06-03 00:18:44 +0200 |
commit | fd1d2992f6bdda19ebaea0761036236f21305cdc (patch) | |
tree | 263b043731fd83b549cdbab826487c8e92c5d3c4 | |
parent | 70d24c5d036cd5787f719104a0ad2f157c5207b1 (diff) | |
download | org-mode-fd1d2992f6bdda19ebaea0761036236f21305cdc.tar.gz |
Make it possible to protect hidden subtrees to be killed by `C-k'
* lisp/org.el (org-ctrl-k-protect-subtree): New option.
(org-kill-line): Protect hidden subtrees if the user wants it.
* doc/org.texi (Headlines): Mention the special behavior of C-k
in headlines.
Scott Otterson writes:
> For what must be the dozenth time, I've just accidentally deleted a
> large tree by typing C-k while in a headline.
>
> This is really easy to do because emacs users have "C-k deletes to the
> end of the line" worn deeply into their neural pathways -- it's so
> automatic for me that the keystroke is close to subconscious. A
> mistaken C-k is especially hard to detect because org-mode displays
> the result exactly like what your subconscious expects, that is, a
> collapsed headline is deleted to the end -- and the tree underneath is
> wiped out with no noticeable warning.
>
> Feature request: add an option preventing tree deletion with C-k
> without user confirmation. Actually, I'd like an option to prevent it
> period.
>
> If this option is already in there, then you're encouraged to tell me
> to RTFM. But then also please tell me where it is, because I can't
> find it.
Carsten replies
> This is now possible due to the variable
> `org-ctrl-k-protect-subtree'. But I predict that you are going to set
> it to nil again soon :D
-rw-r--r-- | doc/org.texi | 13 | ||||
-rw-r--r-- | lisp/org.el | 17 |
2 files changed, 25 insertions, 5 deletions
diff --git a/doc/org.texi b/doc/org.texi index 366d294..50e6dfc 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -787,11 +787,14 @@ command, @command{org-cycle}, which is bound to the @key{TAB} key. @cindex headlines @cindex outline tree @vindex org-special-ctrl-a/e - -Headlines define the structure of an outline tree. The headlines in -Org start with one or more stars, on the left margin@footnote{See -the variable @code{org-special-ctrl-a/e} to configure special behavior -of @kbd{C-a} and @kbd{C-e} in headlines.}. For example: +@vindex org-special-ctrl-k +@vindex org-ctrl-k-protect-subtree + +Headlines define the structure of an outline tree. The headlines in Org +start with one or more stars, on the left margin@footnote{See the variables +@code{org-special-ctrl-a/e}, @code{org-special-ctrl-k}, and +@code{org-ctrl-k-protect-subtree} to configure special behavior of @kbd{C-a}, +@kbd{C-e}, and @kbd{C-k} in headlines.}. For example: @example * Top level headline diff --git a/lisp/org.el b/lisp/org.el index b756963..c3d7d71 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -924,6 +924,18 @@ When t, the following will happen while the cursor is in the headline: :group 'org-edit-structure :type 'boolean) +(defcustom org-ctrl-k-protect-subtree nil + "Non-nil means, do not delete a hidden subtree with C-k. +When set to the symbol `error', simply throw an error when C-k is +used to kill (part-of) a headline that has hidden text behind it. +Any other non-nil value will result in a query to the user, if it is +OK to kill that hidden subtree. When nil, kill without remorse." + :group 'org-edit-structure + :type '(choice + (const :tag "Do not protect hidden subtrees" nil) + (const :tag "Protect hidden subtrees with a security query" t) + (const :tag "Never kill a hidden subtree with C-k" error))) + (defcustom org-yank-folded-subtrees t "Non-nil means when yanking subtrees, fold them. If the kill is a single subtree, or a sequence of subtrees, i.e. if @@ -18568,6 +18580,11 @@ depending on context." ((or (not org-special-ctrl-k) (bolp) (not (org-on-heading-p))) + (if (and (get-char-property (min (point-max) (point-at-eol)) 'invisible) + org-ctrl-k-protect-subtree) + (if (or (eq org-ctrl-k-protect-subtree 'error) + (not (y-or-n-p "Kill hidden subtree along with headline? "))) + (error "C-k aborted - would kill hidden subtree"))) (call-interactively 'kill-line)) ((looking-at (org-re ".*?\\S-\\([ \t]+\\(:[[:alnum:]_@:]+:\\)\\)[ \t]*$")) (kill-region (point) (match-beginning 1)) |