From: Bastien <bzg@altern.org>
To: Carsten Dominik <carsten.dominik@gmail.com>
Cc: emacs-orgmode@gnu.org, Kelly Dean <kellydeanch@yahoo.com>
Subject: Re: Outline and org-mode don't insert text into folded sections logically
Date: Wed, 02 Nov 2011 11:10:38 +0100 [thread overview]
Message-ID: <87aa8eu34y.fsf@altern.org> (raw)
In-Reply-To: <F02240E1-9104-4204-91F6-E5A48FE8667B@gmail.com> (Carsten Dominik's message of "Wed, 2 Nov 2011 08:12:05 +0100")
[-- Attachment #1: Type: text/plain, Size: 1398 bytes --]
Hi Carsten,
Carsten Dominik <carsten.dominik@gmail.com> writes:
> please find enclosed a patch which is my proposal for rounding
> off this feature.
thanks for the clean implementation.
There is a small typo: the second (let ...) should be (let* ...),
see attached updated patch.
> It introduces a variable, applies the check to org-delete-char
> and org-delete-backward-char, and removes the (sit-for 1),
> and it never moves the cursor.
Okay. It also applies the check for `org-self-insert-command'.
I like the variable's name.
Nitpicking:
- (setq org-catch-invisible-edits 'show-and-error) is the same than
(setq org-catch-invisible-edits t), right? Can we document this
somewhere, so that users know what to expect from setting the variable
to t?
- From the docstring: "[...] or add in the middle or right after an
invisible region" -- I agree inserting while in the middle of the
invisible region would feel too unpredictable, but I'd argue that
inserting *right after* the invisible region when point is at the end
of it feels okay. Nevermind, maybe this request will come up later,
I'm fine with your current solution.
> I have been unsing it for a day or two, and I like the `smart'
> setting of the variable. Even though, I do agree with your
> earlier post that the default should be nil.
Okay. Please feel free to apply a patch when you want.
Thanks!
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: checking-for-invisible-edits_bzg.patch --]
[-- Type: text/x-patch, Size: 6158 bytes --]
diff --git a/lisp/org.el b/lisp/org.el
index 318ccfd..d9a8db9 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1065,6 +1065,28 @@ OK to kill that hidden subtree. When nil, kill without remorse."
(const :tag "Protect hidden subtrees with a security query" t)
(const :tag "Never kill a hidden subtree with C-k" error)))
+(defcustom org-catch-invisible-edits nil
+ "Check if in invisible region before inserting or deleting a character.
+Valid values are:
+
+nil Do not check, so just do invisible edits.
+error Throw an error and do nothing.
+show Make point visible, and do the requested edit.
+show-and-error Make point visible, then throw an error and abort the edit.
+smart Make point visible, and do insertion/deletion if it is
+ adjacent to visible text and the change feels predictable.
+ Never delete a previously invisible character or add in the
+ middle or right after an invisible region. Basically, this
+ allows insertion and backward-delete right before ellipses.
+ FIXME: maybe in this case we should not even show?"
+ :group 'org-edit-structure
+ :type '(choice
+ (const :tag "Do not check" nil)
+ (const :tag "Throw error when trying to edit" error)
+ (const :tag "Unhide, but do not do the edit" show-and-error)
+ (const :tag "Show invisible part and do the edit" show)
+ (const :tag "Be smart and do the right thing" smart)))
+
(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
@@ -17401,24 +17423,7 @@ hook. The default setting is `org-speed-command-default-hook'."
If the cursor is in a table looking at whitespace, the whitespace is
overwritten, and the table is not marked as requiring realignment."
(interactive "p")
- (let ((invisible-at-point
- (car (get-char-property-and-overlay (point) 'invisible)))
- (invisible-before-point
- (or (bobp) (car (get-char-property-and-overlay
- (1- (point)) 'invisible)))))
- (when (or (eq invisible-at-point 'outline)
- (eq invisible-at-point 'org-hide-block)
- (eq invisible-before-point 'outline)
- (eq invisible-before-point 'org-hide-block))
- (if (or (eq invisible-before-point 'outline)
- (eq invisible-before-point 'org-hide-block))
- (goto-char (previous-overlay-change (point))))
- (org-cycle)
- (if (or (eq invisible-before-point 'outline)
- (eq invisible-before-point 'org-hide-block))
- (forward-char 1))
- (message "Unfolding invisible region around point before editing")
- (sit-for 1)))
+ (org-check-before-invisible-edit 'insert)
(cond
((and org-use-speed-commands
(setq org-speed-command
@@ -17470,6 +17475,53 @@ overwritten, and the table is not marked as requiring realignment."
(setq org-self-insert-command-undo-counter
(1+ org-self-insert-command-undo-counter))))))))
+(defun org-check-before-invisible-edit (kind)
+ "Check is editing if kind KIND would be dangerous with invisible text around.
+The detailed reaction depends on the user option `org-catch-invisible-edits'."
+ ;; First, try to get out of here as quickly as possible, to reduce overhead
+ (if (and org-catch-invisible-edits
+ (or (not (boundp 'visible-mode)) (not visible-mode))
+ (or (get-char-property (point) 'invisible)
+ (get-char-property (max (point-min) (1- (point))) 'invisible)))
+ ;; OK, we need to take a closer look
+ (let* ((invisible-at-point (get-char-property (point) 'invisible))
+ (invisible-before-point (if (bobp) nil (get-char-property
+ (1- (point)) 'invisible)))
+ (border-and-ok-direction
+ (or
+ ;; Check if we are acting predictably before invisible text
+ (and invisible-at-point (not invisible-before-point)
+ (memq kind '(insert delete-backward)))
+ ;; Check if we are acting predictably after invisible text
+ ;; This works not well, and I have turned it off. It seems
+ ;; better to always show and stop after invisible text.
+ ;; (and (not invisible-at-point) invisible-before-point
+ ;; (memq kind '(insert delete)))
+ )))
+
+ (when (or (memq invisible-at-point '(outline org-hide-block))
+ (memq invisible-before-point '(outline org-hide-block)))
+ (if (eq org-catch-invisible-edits 'error)
+ (error "Editing in invisible areas is prohibited - make visible first"))
+ ;; Make the area visible
+ (save-excursion
+ (if invisible-before-point
+ (goto-char (previous-single-char-property-change
+ (point) 'invisible)))
+ (org-cycle))
+ (cond
+ ((eq org-catch-invisible-edits 'show)
+ ;; That's it, we do the edit after showing
+ (message
+ "Unfolding invisible region around point before editing")
+ (sit-for 1))
+ ((and (eq org-catch-invisible-edits 'smart)
+ border-and-ok-direction)
+ (message "Unfolding invisible region around point before editing"))
+ (t
+ ;; Don't do the edit, make the user repeat it in full visibility
+ (error "Edit in invisible region aborted, repeat to confirm with text visible")))))))
+
(defun org-fix-tags-on-the-fly ()
(when (and (equal (char-after (point-at-bol)) ?*)
(org-on-heading-p))
@@ -17482,6 +17534,7 @@ front of the next \"|\" separator, to keep the table aligned. The table will
still be marked for re-alignment if the field did fill the entire column,
because, in this case the deletion might narrow the column."
(interactive "p")
+ (org-check-before-invisible-edit 'delete-backward)
(if (and (org-table-p)
(eq N 1)
(string-match "|" (buffer-substring (point-at-bol) (point)))
@@ -17508,6 +17561,7 @@ front of the next \"|\" separator, to keep the table aligned. The table will
still be marked for re-alignment if the field did fill the entire column,
because, in this case the deletion might narrow the column."
(interactive "p")
+ (org-check-before-invisible-edit 'delete)
(if (and (org-table-p)
(not (bolp))
(not (= (char-after) ?|))
[-- Attachment #3: Type: text/plain, Size: 14 bytes --]
--
Bastien
next prev parent reply other threads:[~2011-11-02 12:19 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-03 19:14 Outline and org-mode don't insert text into folded sections logically Kelly Dean
2011-09-05 7:52 ` Giovanni Ridolfi
2011-09-05 8:01 ` suvayu ali
2011-10-22 10:13 ` Bastien
2011-10-22 10:17 ` suvayu ali
2011-10-22 10:21 ` Jambunathan K
2011-10-22 13:53 ` Bastien
2011-10-23 2:18 ` suvayu ali
2011-10-29 14:10 ` Bastien
2011-10-29 14:57 ` suvayu ali
2011-10-29 15:40 ` Bastien
2011-10-29 15:53 ` suvayu ali
2011-10-29 16:15 ` Bastien
2011-10-29 16:22 ` suvayu ali
2011-10-30 1:07 ` Bastien
2011-10-30 6:28 ` Carsten Dominik
2011-10-30 7:30 ` Jambunathan K
2011-10-30 7:47 ` Carsten Dominik
2011-10-30 9:04 ` Bastien
2011-10-30 15:37 ` Carsten Dominik
2011-10-31 20:58 ` Carsten Dominik
2011-11-02 7:12 ` Carsten Dominik
2011-11-02 10:10 ` Bastien [this message]
2011-11-02 12:53 ` Carsten Dominik
2011-11-03 1:30 ` Bastien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87aa8eu34y.fsf@altern.org \
--to=bzg@altern.org \
--cc=carsten.dominik@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=kellydeanch@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).