[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] [PATCH 2/2] Prevent deletion of newline added by narrowing
From: |
Leo Vivier |
Subject: |
[O] [PATCH 2/2] Prevent deletion of newline added by narrowing |
Date: |
Mon, 18 Feb 2019 01:25:47 +0100 |
* 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 &optional region)
+ (interactive (list (mark) (point) 'region))
+ (kill-region
+ beg
+ end
+ region)
+ (save-excursion
+ (when (eobp)
+ (insert "\n"))))
+
(defun org-yank (&optional 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] [PATCH 1/2] Fix narrowing for 1-line subtrees, Leo Vivier, 2019/02/17
- [O] [PATCH 2/2] Prevent deletion of newline added by narrowing,
Leo Vivier <=
- Re: [O] [PATCH 1/2] Fix narrowing for 1-line subtrees, Nicolas Goaziou, 2019/02/19
- Re: [O] [PATCH 1/2] Fix narrowing for 1-line subtrees, Leo Vivier, 2019/02/19
- [O] [PATCH] Fix narrowing for 1-line subtrees (squashed), Leo Vivier, 2019/02/19
- Re: [O] [PATCH 1/2] Fix narrowing for 1-line subtrees, Nicolas Goaziou, 2019/02/19
- Re: [O] [PATCH 1/2] Fix narrowing for 1-line subtrees, Leo Vivier, 2019/02/19
- Re: [O] [PATCH 1/2] Fix narrowing for 1-line subtrees, Leo Vivier, 2019/02/19
- Re: [O] [PATCH 1/2] Fix narrowing for 1-line subtrees, Leo Vivier, 2019/02/19