all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [RFC] Change visibility for bracket links
@ 2016-10-05 15:40 Nicolas Goaziou
  2016-10-05 15:46 ` Rainer M Krug
                   ` (8 more replies)
  0 siblings, 9 replies; 49+ messages in thread
From: Nicolas Goaziou @ 2016-10-05 15:40 UTC (permalink / raw)
  To: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 1516 bytes --]

Hello,

I'd like to make the following change to bracket links display (i.e.,
when `org-highlight-links' contains `bracket', which is the default).

Basically, I want to leave a visible pair of brackets around the link,
i.e.,

  [[uri][description]]

is displayed as

  [description]

instead of

  description

and

  [[uri]]

is displayed as

  [uri]

instead of

  uri

The rationale behind this suggestion is that editing a mostly invisible
link is unintuitive when point is at the boundaries of its visible part.

More precisely, in the following visible part of a link

  description

if point hits "d" from the right, changes happen in the description of
the link, but if point comes from the left, changes happen before the
link. 

I guess I could get used to it, but sometimes, the link happens to be at
column 0. In this case, the only way to "come from the left" is to move
to the previous line and go past the newline character. This is, IMO,
very annoying, notwithstanding the fact that it is impossible to realize
at the beginning of the buffer.

Leaving a pair of brackets, OTOH, disambiguates the situation. Editing
before the opening bracket makes changes before the link. Conversely,
editing after the former makes changes to the uri or the description,
whichever is displayed.

The cost a little more visual clutter, but it seems very acceptable to
me. I attach a quick patch for testing.

Feedback welcome.

Regards,

-- 
Nicolas Goaziou                                                0x80A93738

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Change-bracket-links-visibility.patch --]
[-- Type: text/x-diff, Size: 4080 bytes --]

From 768d77be335e1e5e0a4afa9bf7dbd89f9c5ab65e Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Wed, 5 Oct 2016 17:22:15 +0200
Subject: [PATCH] Change bracket links visibility

* lisp/org.el (org-activate-bracket-links): Leave a pair of brackets
  around bracket links so as to facilitate editing them.
---
 lisp/org.el | 49 ++++++++++++++++++-------------------------------
 1 file changed, 18 insertions(+), 31 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 6d5201b..25f48e3 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6199,41 +6199,34 @@ by a #."
 			  (t
 			   `(:uri ,(format "%s:%s" type path)))))
 	   (activate-func (org-link-get-parameter type :activate-func))
-	   ;; invisible part
-	   (ip (list 'invisible (or
-				 (org-link-get-parameter type :display)
-				 'org-link)
-		     'face face
-		     'keymap keymap
-		     'mouse-face mouse-face
-		     'font-lock-multiline t
-		     'help-echo help
-		     'htmlize-link htmlize-link))
-	   ;; visible part
+	   ;; Visible part.
 	   (vp (list 'keymap keymap
 		     'face face
 		     'mouse-face mouse-face
 		     'font-lock-multiline t
 		     'help-echo help
-		     'htmlize-link htmlize-link)))
+		     'htmlize-link htmlize-link))
+	   ;; Invisible part.
+	   (ip (append (list 'invisible
+			     (or (org-link-get-parameter type :display)
+				 'org-link))
+		       vp)))
       ;; We need to remove the invisible property here.  Table narrowing
       ;; may have made some of this invisible.
       (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
       (remove-text-properties (match-beginning 0) (match-end 0)
 			      '(invisible nil))
-      (if (match-end 3)
+      (if (match-end 2)
 	  (progn
-	    (add-text-properties (match-beginning 0) (match-beginning 3) ip)
-	    (org-rear-nonsticky-at (match-beginning 3))
-	    (add-text-properties (match-beginning 3) (match-end 3) vp)
-	    (org-rear-nonsticky-at (match-end 3))
-	    (add-text-properties (match-end 3) (match-end 0) ip)
+	    (add-text-properties (match-beginning 0) (match-beginning 2) ip)
+	    (add-text-properties (match-beginning 2) (match-end 2) vp)
+	    (add-text-properties (match-end 2) (match-end 0) ip)
+	    ;; The following is needed so as characters inserted after
+	    ;; the closing bracket do not enter the link.
 	    (org-rear-nonsticky-at (match-end 0)))
-	(add-text-properties (match-beginning 0) (match-beginning 1) ip)
-	(org-rear-nonsticky-at (match-beginning 1))
-	(add-text-properties (match-beginning 1) (match-end 1) vp)
-	(org-rear-nonsticky-at (match-end 1))
-	(add-text-properties (match-end 1) (match-end 0) ip)
+	(add-text-properties (match-beginning 0) (1+ (match-beginning 0)) ip)
+	(add-text-properties (1+ (match-beginning 0)) (1+ (match-end 1)) vp)
+	(add-text-properties (1+ (match-end 1)) (match-end 0) ip)
 	(org-rear-nonsticky-at (match-end 0)))
       (when activate-func
 	(funcall activate-func link-start link-end path bracketp))
@@ -23762,10 +23755,7 @@ beyond the end of the headline."
 	    ;; point was already at beginning of line and command is
 	    ;; repeated.
 	    (when (and (= (point) pos) (eq last-command this-command))
-	      (goto-char after-bullet))))))))
-  (setq disable-point-adjustment
-        (or (not (invisible-p (point)))
-            (not (invisible-p (max (point-min) (1- (point))))))))
+	      (goto-char after-bullet)))))))))
 
 (defun org-end-of-line (&optional arg)
   "Go to the end of the line.
@@ -23802,10 +23792,7 @@ the cursor is already beyond the end of the headline."
 	  ;; If element is hidden, `move-end-of-line' would put point
 	  ;; after it.  Use `end-of-line' to stay on current line.
 	  (call-interactively 'end-of-line))
-	 (t (call-interactively move-fun))))))
-  (setq disable-point-adjustment
-        (or (not (invisible-p (point)))
-            (not (invisible-p (max (point-min) (1- (point))))))))
+	 (t (call-interactively move-fun)))))))
 
 (define-key org-mode-map "\C-a" 'org-beginning-of-line)
 (define-key org-mode-map "\C-e" 'org-end-of-line)
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2016-10-22  1:02 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-05 15:40 [RFC] Change visibility for bracket links Nicolas Goaziou
2016-10-05 15:46 ` Rainer M Krug
2016-10-05 16:46 ` Marco Wahl
2016-10-05 21:13   ` Nicolas Goaziou
2016-10-05 19:21 ` Detlef Steuer
     [not found] ` <520C9DD6-7764-4B07-8E7A-FB42CC0CDF8A@dagertech.net>
2016-10-05 21:30   ` David A. Gershman
2016-10-05 22:26     ` Nicolas Goaziou
2016-10-06  0:16       ` David A. Gershman
2016-10-06  0:27         ` Clément Pit--Claudel
2016-10-07  6:13           ` Nicolas Goaziou
2016-10-12  9:27             ` Rasmus
     [not found]         ` <e78992df838c44419e7893671dbe2adb@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2016-10-06  7:38           ` Eric S Fraga
2016-10-06 14:53             ` William Denton
2016-10-08  2:38 ` Adam Porter
2016-10-08  3:50   ` Clément Pit--Claudel
2016-10-08  4:00     ` Adam Porter
2016-10-10 14:17     ` Nick Dokos
2016-10-10 14:56       ` Clément Pit--Claudel
2016-10-10 16:28         ` Nick Dokos
2016-10-14 20:00         ` Joost Kremers
2016-10-14 21:24           ` Thomas S. Dye
2016-10-12  7:10 ` Daniele Nicolodi
2016-10-12 10:37   ` Nicolas Goaziou
2016-10-12 10:40     ` Nicolas Goaziou
2016-10-12 17:36     ` Daniele Nicolodi
2016-10-13 12:07       ` Nicolas Goaziou
2016-10-13 12:28         ` Aaron Ecay
2016-10-13 12:35           ` Nicolas Goaziou
2016-10-13 13:20             ` Michael Brand
2016-10-13 18:23               ` Nicolas Goaziou
2016-10-13 17:46             ` Gregor Zattler
2016-10-13 22:05             ` [RFC] " Aaron Ecay
2016-10-13 17:31         ` Daniele Nicolodi
2016-10-13 18:33           ` Nicolas Goaziou
2016-10-13 19:11           ` William Denton
2016-10-12  9:23 ` Rasmus
2016-10-12 10:32   ` Nicolas Goaziou
2016-10-12 11:08     ` Rasmus
2016-10-12 12:21       ` Nicolas Goaziou
2016-10-12 12:47         ` Rasmus
2016-10-13 12:30           ` Nicolas Goaziou
2016-10-20 23:44             ` Clément Pit--Claudel
2016-10-22  1:02               ` Stig Brautaset
2016-10-13 12:19 ` Rasmus
2016-10-13 16:13   ` Nick Dokos
2016-10-13 16:24     ` Rasmus
2016-10-13 16:43     ` Clément Pit--Claudel
2016-10-13 17:18       ` Nick Dokos
2016-10-13 12:19 ` Rasmus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.