unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] mouse-1 click follows link
@ 2004-10-29 13:04 Kim F. Storm
  2004-10-29 23:54 ` Luc Teirlinck
  0 siblings, 1 reply; 28+ messages in thread
From: Kim F. Storm @ 2004-10-29 13:04 UTC (permalink / raw)



Here is the full patch (without doc updates) for the proposed
mouse-1-click-follows-link functionality, including rewriting of
tooltips and making C-h k aware of the remapping.

Index: mouse.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/mouse.el,v
retrieving revision 1.253
diff -c -r1.253 mouse.el
*** mouse.el	28 Oct 2004 23:33:23 -0000	1.253
--- mouse.el	29 Oct 2004 12:57:49 -0000
***************
*** 48,53 ****
--- 48,77 ----
    :type 'boolean
    :group 'mouse)
  
+ (defcustom mouse-1-click-follows-link 350
+   "Non-nil means that clicking mouse-1 on a link follows the link.
+ This is only done for links which have the mouse-face property.
+ 
+ If value is the symbol double, a double click follows the link.
+ 
+ If value is an integer, the time elapsed between pressing and
+ releasing the mouse button determines whether to follow the link
+ or perform the normal mouse-1 action (typically set point).
+ The absolute numeric value specifices the maximum duration of a
+ \"short click\" in milli-seconds.  A positive value means that a
+ short click follows the link, and a longer click performs the
+ normal action.  A negative value gives the opposite behaviour.
+ 
+ Otherwise, a single mouse-1 click unconditionally follows the link.
+ 
+ Note that dragging the mouse never follows the link."
+   :version "21.4"
+   :type '(choice (const :tag "Disabled" nil)
+ 		 (const :tag "Double click" double)
+                  (number :tag "Single click time limit" :value 350)
+                  (other :tag "Single click" t))
+   :group 'mouse)
+ 
  \f
  ;; Provide a mode-specific menu on a mouse button.
  
***************
*** 731,736 ****
--- 755,764 ----
        (run-hooks 'mouse-leave-buffer-hook)
        (mouse-drag-region-1 start-event))))
  
+ (defun mouse-on-link-p (pos)
+   (and (get-char-property pos 'mouse-face)
+        (not (get-char-property pos 'dont-follow-link))))
+ 
  (defun mouse-drag-region-1 (start-event)
    (mouse-minibuffer-check start-event)
    (let* ((echo-keystrokes 0)
***************
*** 746,751 ****
--- 774,780 ----
  		     (nth 3 bounds)
  		   ;; Don't count the mode line.
  		   (1- (nth 3 bounds))))
+ 	 on-link remap-double-click
  	 (click-count (1- (event-click-count start-event))))
      (setq mouse-selection-click-count click-count)
      (setq mouse-selection-click-count-buffer (current-buffer))
***************
*** 755,760 ****
--- 784,796 ----
      (if (< (point) start-point)
  	(goto-char start-point))
      (setq start-point (point))
+     (setq on-link (and mouse-1-click-follows-link
+ 		       (mouse-on-link-p start-point)))
+     (setq remap-double-click (and on-link
+ 				  (eq mouse-1-click-follows-link 'double)
+ 				  (= click-count 1)))
+     (if remap-double-click  ;; Don't expand mouse overlay in links
+ 	(setq click-count 0))
      (let ((range (mouse-start-end start-point start-point click-count)))
        (move-overlay mouse-drag-overlay (car range) (nth 1 range)
  		    (window-buffer start-window))
***************
*** 877,882 ****
--- 913,938 ----
  			 (or end-point
  			     (= (window-start start-window)
  				start-window-start)))
+ 		(if (and on-link
+ 			 (not end-point)
+ 			 (consp event)
+ 			 (or remap-double-click
+ 			     (and
+ 			      (not (eq mouse-1-click-follows-link 'double))
+ 			      (= click-count 0)
+ 			      (= (event-click-count event) 1)
+ 			      (not (input-pending-p))
+ 			      (or (not (integerp mouse-1-click-follows-link))
+ 				  (let ((t0 (posn-timestamp (event-start start-event)))
+ 					(t1 (posn-timestamp (event-end event))))
+ 				    (and (integerp t0) (integerp t1)
+ 					 (if (> mouse-1-click-follows-link 0)
+ 					     (<= (- t1 t0) mouse-1-click-follows-link)
+ 					   (< (- t0 t1) mouse-1-click-follows-link)))))
+ 			      (or (not double-click-time)
+ 				  (sit-for 0 (if (integerp double-click-time)
+ 						 double-click-time 500) t)))))
+ 		    (setcar event 'mouse-2))
  		(setq unread-command-events
  		      (cons event unread-command-events)))))
  	(delete-overlay mouse-drag-overlay)))))

*** help.el	25 Oct 2004 14:43:57 +0200	1.270
--- help.el	29 Oct 2004 12:35:18 +0200	
***************
*** 609,625 ****
  	    (princ "\n   which is ")
  	    (describe-function-1 defn)
  	    (when up-event
! 	      (let ((defn (or (string-key-binding up-event) (key-binding up-event))))
  		(unless (or (null defn) (integerp defn) (equal defn 'undefined))
! 		  (princ "\n\n-------------- up event ---------------\n\n")
! 		  (princ (key-description up-event))
  		  (if (windowp window)
  		      (princ " at that spot"))
  		  (princ " runs the command ")
  		  (prin1 defn)
  		  (princ "\n   which is ")
! 		  (describe-function-1 defn))))
! 	    (print-help-return-message)))))))
  
  \f
  (defun describe-mode (&optional buffer)
--- 609,666 ----
  	    (princ "\n   which is ")
  	    (describe-function-1 defn)
  	    (when up-event
! 	      (let ((ev (aref up-event 0))
! 		    (descr (key-description up-event))
! 		    (hdr "\n\n-------------- up event ---------------\n\n")
! 		    defn
! 		    mouse-1-tricky mouse-1-remapped)
! 		(when (and (consp ev)
! 			   (eq (car ev) 'mouse-1)
! 			   (windowp window)
! 			   mouse-1-click-follows-link
! 			   (not (eq mouse-1-click-follows-link 'double))
! 			   (with-current-buffer (window-buffer window)
! 			     (mouse-on-link-p (posn-point (event-start ev)))))
! 		  (setq mouse-1-tricky (integerp mouse-1-click-follows-link)
! 			mouse-1-remapped (or (not mouse-1-tricky)
! 					     (> mouse-1-click-follows-link 0)))
! 		  (if mouse-1-remapped
! 		      (setcar ev 'mouse-2)))
! 		(setq defn (or (string-key-binding up-event) (key-binding up-event)))
  		(unless (or (null defn) (integerp defn) (equal defn 'undefined))
! 		  (princ (if mouse-1-tricky
! 			     "\n\n----------------- up-event (short click) ----------------\n\n"
! 			   hdr))
! 		  (setq hdr nil)
! 		  (princ descr)
  		  (if (windowp window)
  		      (princ " at that spot"))
+ 		  (if mouse-1-remapped
+ 		      (princ " is remapped to <mouse-2>\n  which" ))
  		  (princ " runs the command ")
  		  (prin1 defn)
  		  (princ "\n   which is ")
! 		  (describe-function-1 defn))
! 		(when mouse-1-tricky
! 		  (setcar ev
! 			  (if (> mouse-1-click-follows-link 0) 'mouse-1 'mouse-2))
! 		  (setq defn (or (string-key-binding up-event) (key-binding up-event)))
! 		  (unless (or (null defn) (integerp defn) (equal defn 'undefined))
! 		    (princ (or hdr
! 			       "\n\n----------------- up-event (long click) ----------------\n\n"))
! 		    (princ "Pressing ")
! 		    (princ descr)
! 		    (if (windowp window)
! 			(princ " at that spot"))
! 		    (princ (format " for longer than %d milli-seconds\n"
! 				   (abs mouse-1-click-follows-link)))
! 		    (if (not mouse-1-remapped)
! 			(princ " remaps it to <mouse-2> which" ))
! 		    (princ " runs the command ")
! 		    (prin1 defn)
! 		    (princ "\n   which is ")
! 		    (describe-function-1 defn))))
! 	    (print-help-return-message))))))))
  
  \f
  (defun describe-mode (&optional buffer)

*** tooltip.el	01 Sep 2003 17:45:17 +0200	1.34
--- tooltip.el	29 Oct 2004 12:36:23 +0200	
***************
*** 480,486 ****
  (defun tooltip-show-help-function (msg)
    "Function installed as `show-help-function'.
  MSG is either a help string to display, or nil to cancel the display."
!   (let ((previous-help tooltip-help-message))
      (setq tooltip-help-message msg)
      (cond ((null msg)
  	   ;; Cancel display.  This also cancels a delayed tip, if
--- 481,505 ----
  (defun tooltip-show-help-function (msg)
    "Function installed as `show-help-function'.
  MSG is either a help string to display, or nil to cancel the display."
!   (let ((previous-help tooltip-help-message)
! 	mp pos)
!     (if (and mouse-1-click-follows-link
! 	     (stringp msg)
! 	     (save-match-data
! 	       (string-match "^mouse-2" msg))
! 	     (setq mp (mouse-pixel-position))
! 	     (consp (setq pos (cdr mp)))
! 	     (setq pos (posn-at-x-y (car pos) (cdr pos) (car mp)))
! 	     (windowp (posn-window pos)))
! 	(with-current-buffer (window-buffer (posn-window pos))
! 	  (if (mouse-on-link-p (posn-point pos))
! 	      (setq msg (concat
! 		    (cond
! 		     ((eq mouse-1-click-follows-link 'double) "double-")
! 		     ((and (integerp mouse-1-click-follows-link)
! 			   (< mouse-1-click-follows-link 0)) "Long ")
! 		     (t ""))
! 		    "mouse-1" (substring msg 7))))))
      (setq tooltip-help-message msg)
      (cond ((null msg)
  	   ;; Cancel display.  This also cancels a delayed tip, if

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-29 13:04 [PATCH] mouse-1 click follows link Kim F. Storm
@ 2004-10-29 23:54 ` Luc Teirlinck
  2004-10-30 22:04   ` Kim F. Storm
  0 siblings, 1 reply; 28+ messages in thread
From: Luc Teirlinck @ 2004-10-29 23:54 UTC (permalink / raw)
  Cc: emacs-devel

Kim Storm wrote:

   Here is the full patch (without doc updates) for the proposed
   mouse-1-click-follows-link functionality, including rewriting of
   tooltips and making C-h k aware of the remapping.

I do not have the time to read your patch in detail.  I hope that I am
wrong, but at first view it looks as if you do:

    (setcar event 'mouse-2)

whenever the user clicked mouse-1 and the text has the mouse-face
property and does not have the new dont-follow-link property.
Hopefully I am misunderstanding this, as it would obviously be
disastrous, even for an optional feature.

Having the mouse-face property does _not at all_ imply that the text
is a link.  I would rather work with a `link' property if you want to
remap, than with a `dont-follow-link' if not.

Sincerely,

Luc.

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-29 23:54 ` Luc Teirlinck
@ 2004-10-30 22:04   ` Kim F. Storm
  2004-10-31  0:09     ` Luc Teirlinck
  2004-10-31  0:34     ` Luc Teirlinck
  0 siblings, 2 replies; 28+ messages in thread
From: Kim F. Storm @ 2004-10-30 22:04 UTC (permalink / raw)
  Cc: emacs-devel

Luc Teirlinck <teirllm@dms.auburn.edu> writes:

> Kim Storm wrote:
>
>    Here is the full patch (without doc updates) for the proposed
>    mouse-1-click-follows-link functionality, including rewriting of
>    tooltips and making C-h k aware of the remapping.
>
> I do not have the time to read your patch in detail.  I hope that I am
> wrong, but at first view it looks as if you do:
>
>     (setcar event 'mouse-2)
>
> whenever the user clicked mouse-1 and the text has the mouse-face
> property and does not have the new dont-follow-link property.

Exactly.

> Hopefully I am misunderstanding this, as it would obviously be
> disastrous, even for an optional feature.

Can you elaborate on this?

>
> Having the mouse-face property does _not at all_ imply that the text
> is a link.  

So far we have identified two examples of this in external packages
(preview-latex and AUCtex) -- it would be trivial for those to
add the dont-follow-link property.

>             I would rather work with a `link' property if you want to
> remap, than with a `dont-follow-link' if not.

I think it is better to mark the exceptions, rather than the rule.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-30 22:04   ` Kim F. Storm
@ 2004-10-31  0:09     ` Luc Teirlinck
  2004-10-31 12:49       ` Kim F. Storm
  2004-11-01  7:24       ` Richard Stallman
  2004-10-31  0:34     ` Luc Teirlinck
  1 sibling, 2 replies; 28+ messages in thread
From: Luc Teirlinck @ 2004-10-31  0:09 UTC (permalink / raw)
  Cc: emacs-devel

Kim Storm wrote:

   > Hopefully I am misunderstanding this, as it would obviously be
   > disastrous, even for an optional feature.

   Can you elaborate on this?

Yes.  You blindly rebind mouse-1 to mouse-2 without having the
_slightest_ idea what mouse-2 is bound to.  This is reckless and
obviously unacceptable.  It represents a danger to the unsuspecting
user, who will only expect the rebinding for true links.

You expect package authors to adapt to your change, but it is
completely unrealistic to expect all of them to do that.  Most package
authors do not read Emacs devel.  Also, even if by some miracle all
package authors would do that, then this would _still_ not solve the
problem.  The user may upgrade to a new Emacs version without
upgrading all outside packages he uses.

   So far we have identified two examples of this in external packages
   (preview-latex and AUCtex) -- it would be trivial for those to
   add the dont-follow-link property.

It is not only non-trivial but impossible to check all external packages.
I could be wrong, but I have the impression that you did not even
check all uses of the mouse-face property that are included with the
Emacs distribution.

   I think it is better to mark the exceptions, rather than the rule.

I am not sure that they are the exception, if you count uses of the
mouse-face property in the source code, rather than occurrences in
actual Emacs buffers.  But anyway, this is irrelevant, because it
quite simply would be irresponsible to blindly execute some random
command, regardless of whether such a blind execution occurs in 90
percent or .01 percent of the cases.  The danger is too big.

On the other hand, if the behavior only occurs when the text has the
link property, then it only occurs for things somebody has explicitly
checked.  The only thing that can happen for overlooked "true" links
is that mouse-1 sets point instead of following the link.  No real
harm happened and the user can file a bug report.  Eventually all real
links will be accounted for.

Even though only implementing the behavior for text that has been
explicitly given the link property would be a lot better than the
concrete patch you proposed, I still do not believe that it would be
ideal.  Unlike your concrete patch, I believe that it would be
acceptable, but I believe that there _must_ be simpler and better ways
to get the same effect.

Sincerely,

Luc.

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-30 22:04   ` Kim F. Storm
  2004-10-31  0:09     ` Luc Teirlinck
@ 2004-10-31  0:34     ` Luc Teirlinck
  2004-10-31 12:53       ` Kim F. Storm
  1 sibling, 1 reply; 28+ messages in thread
From: Luc Teirlinck @ 2004-10-31  0:34 UTC (permalink / raw)
  Cc: emacs-devel

As I already said, I believe that there _must_ be substantially better
ways to give users the option to have web browser style bindings for
true links than the one you proposed.

We could have a common parent keymap for true links, that is text with
the `link' property.  There could be several predefined values for
that keymap.  At least two: "Classical Emacs" and "Web Browser".  But
the user could customize the keymap any way he wanted and specialized
links could extend it with their own bindings.

This has the advantage that the user who chooses "Web Browser" could
bind mouse-2 to anything he wanted (different from mouse-1), which he
can not do with your patch.

Why is all of this suddenly so urgent?  If we waited till after the
21.4 release, then we could have a solid and well tested high quality
implementation, rather than some hastily thrown together stuff.

Sincerely,

Luc.

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31  0:09     ` Luc Teirlinck
@ 2004-10-31 12:49       ` Kim F. Storm
  2004-11-01  7:24       ` Richard Stallman
  1 sibling, 0 replies; 28+ messages in thread
From: Kim F. Storm @ 2004-10-31 12:49 UTC (permalink / raw)
  Cc: emacs-devel

Luc Teirlinck <teirllm@dms.auburn.edu> writes:

> Kim Storm wrote:
>
>    > Hopefully I am misunderstanding this, as it would obviously be
>    > disastrous, even for an optional feature.
>
>    Can you elaborate on this?
>
> Yes.  You blindly rebind mouse-1 to mouse-2 without having the
> _slightest_ idea what mouse-2 is bound to.

That's true.

> On the other hand, if the behavior only occurs when the text has the
> link property, then it only occurs for things somebody has explicitly
> checked.  The only thing that can happen for overlooked "true" links
> is that mouse-1 sets point instead of following the link.  No real
> harm happened and the user can file a bug report.  Eventually all real
> links will be accounted for.

Hm.  I'm starting to agree that the blind remapping is too intrusive.

A non-nil 'link property is definitely a safer mechanism to recognize
when this feature should be activated.

I'll think more about this approach.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31  0:34     ` Luc Teirlinck
@ 2004-10-31 12:53       ` Kim F. Storm
  2004-10-31 15:24         ` Luc Teirlinck
  2004-11-27  0:44         ` [NEW PATCH] " Kim F. Storm
  0 siblings, 2 replies; 28+ messages in thread
From: Kim F. Storm @ 2004-10-31 12:53 UTC (permalink / raw)
  Cc: emacs-devel

Luc Teirlinck <teirllm@dms.auburn.edu> writes:

> As I already said, I believe that there _must_ be substantially better
> ways to give users the option to have web browser style bindings for
> true links than the one you proposed.
>
> We could have a common parent keymap for true links, that is text with
> the `link' property.  There could be several predefined values for
> that keymap.  At least two: "Classical Emacs" and "Web Browser".  But
> the user could customize the keymap any way he wanted and specialized
> links could extend it with their own bindings.

I don't see how this would work -- the mouse-2 binding is typically
made in a keymap property on the link itself, as even things that
_are_ links use different bindings for mouse-2.

So how can you use a global map for links ?

>
> This has the advantage that the user who chooses "Web Browser" could
> bind mouse-2 to anything he wanted (different from mouse-1), which he
> can not do with your patch.

But only on links -- and the code in question would have to react
based on the specific kind of link.

I think this is unnecessary complexity.

>
> Why is all of this suddenly so urgent?  If we waited till after the
> 21.4 release, then we could have a solid and well tested high quality
> implementation, rather than some hastily thrown together stuff.

I would prefer this to be fixed before 2007.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31 12:53       ` Kim F. Storm
@ 2004-10-31 15:24         ` Luc Teirlinck
  2004-10-31 18:37           ` David Kastrup
  2004-11-27  0:44         ` [NEW PATCH] " Kim F. Storm
  1 sibling, 1 reply; 28+ messages in thread
From: Luc Teirlinck @ 2004-10-31 15:24 UTC (permalink / raw)
  Cc: emacs-devel

Kim Storm wrote:

   I don't see how this would work -- the mouse-2 binding is typically
   made in a keymap property on the link itself, as even things that
   _are_ links use different bindings for mouse-2.

   So how can you use a global map for links ?

I was thinking of a common _parent_ keymap, say `link-keymap' for
links.  In fact, no separate `link' property would be needed.  Each
kind of link would use its individual keymap, but would do:

(set-keymap-parent this-keymap link-keymap)

link-keymap would be a customizable variable with predefined values.

Maybe there are problems with this, but I do not immediately see them.

Sincerely,

Luc.

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31 15:24         ` Luc Teirlinck
@ 2004-10-31 18:37           ` David Kastrup
  2004-10-31 20:03             ` Luc Teirlinck
  2004-10-31 21:40             ` Stefan
  0 siblings, 2 replies; 28+ messages in thread
From: David Kastrup @ 2004-10-31 18:37 UTC (permalink / raw)
  Cc: emacs-devel, storm

Luc Teirlinck <teirllm@dms.auburn.edu> writes:

> Kim Storm wrote:
>
>    I don't see how this would work -- the mouse-2 binding is typically
>    made in a keymap property on the link itself, as even things that
>    _are_ links use different bindings for mouse-2.
>
>    So how can you use a global map for links ?
>
> I was thinking of a common _parent_ keymap, say `link-keymap' for
> links.  In fact, no separate `link' property would be needed.  Each
> kind of link would use its individual keymap, but would do:
>
> (set-keymap-parent this-keymap link-keymap)
>
> link-keymap would be a customizable variable with predefined values.
>
> Maybe there are problems with this, but I do not immediately see them.

What would the keybinding in link-keymap be?  It has to resolve to
something different for each link.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31 18:37           ` David Kastrup
@ 2004-10-31 20:03             ` Luc Teirlinck
  2004-10-31 20:13               ` David Kastrup
  2004-10-31 21:40             ` Stefan
  1 sibling, 1 reply; 28+ messages in thread
From: Luc Teirlinck @ 2004-10-31 20:03 UTC (permalink / raw)
  Cc: storm, emacs-devel

David Kastrup wrote:

   What would the keybinding in link-keymap be?  It has to resolve to
   something different for each link.

Things like mouse-set-point, mouse-drag-region and the like would be
common.  It would seem that we are only talking about the link-following.
That would then have to be 

(lambda (arg) (funcall mouse-follow-link-function arg))

where arg is the numeric prefix.

Sincerely,

Luc.

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31 20:03             ` Luc Teirlinck
@ 2004-10-31 20:13               ` David Kastrup
  0 siblings, 0 replies; 28+ messages in thread
From: David Kastrup @ 2004-10-31 20:13 UTC (permalink / raw)
  Cc: storm, emacs-devel

Luc Teirlinck <teirllm@dms.auburn.edu> writes:

> David Kastrup wrote:
>
>    What would the keybinding in link-keymap be?  It has to resolve to
>    something different for each link.
>
> Things like mouse-set-point, mouse-drag-region and the like would be
> common.  It would seem that we are only talking about the link-following.
> That would then have to be 
>
> (lambda (arg) (funcall mouse-follow-link-function arg))
>
> where arg is the numeric prefix.

But that does not make it possible to have different actions on
different active links in a buffer.

Currently I can add a local keymap just doing anything on a
mouse-click without worrying about the buffer-local
mouse-follow-link-function setting.  Not all clickable buttons are
strictly major-mode dependent.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31 18:37           ` David Kastrup
  2004-10-31 20:03             ` Luc Teirlinck
@ 2004-10-31 21:40             ` Stefan
  2004-10-31 23:39               ` Kim F. Storm
  1 sibling, 1 reply; 28+ messages in thread
From: Stefan @ 2004-10-31 21:40 UTC (permalink / raw)
  Cc: storm, Luc Teirlinck, emacs-devel

> What would the keybinding in link-keymap be?  It has to resolve to
> something different for each link.

Yes, that's a problem.  Here are some ideas:

1 - (define-key link-parent-map [mouse-1] [mouse-2])
    (define-key this-button-keymap [mouse-2] 'foobar)

2 - (define-key link-parent-map [mouse-1] [follow-link])
    (define-key this-button-keymap [follow-link] 'foobar)

3 - (define-key link-parent-map [mouse-1] 'follow-link-command)
    (define-key this-button-keymap [remap follow-link-command] 'foobar)


-- Stefan

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31 21:40             ` Stefan
@ 2004-10-31 23:39               ` Kim F. Storm
  2004-11-01  0:33                 ` Stefan
  0 siblings, 1 reply; 28+ messages in thread
From: Kim F. Storm @ 2004-10-31 23:39 UTC (permalink / raw)
  Cc: Luc Teirlinck, emacs-devel

Stefan <monnier@iro.umontreal.ca> writes:

>> What would the keybinding in link-keymap be?  It has to resolve to
>> something different for each link.
>
> Yes, that's a problem.  Here are some ideas:
>
> 1 - (define-key link-parent-map [mouse-1] [mouse-2])
>     (define-key this-button-keymap [mouse-2] 'foobar)
>
> 2 - (define-key link-parent-map [mouse-1] [follow-link])
>     (define-key this-button-keymap [follow-link] 'foobar)
>
> 3 - (define-key link-parent-map [mouse-1] 'follow-link-command)
>     (define-key this-button-keymap [remap follow-link-command] 'foobar)


Yes, this would work quite nicely!

I prefer #2 -- it looks nice in this-button-keymap.

A way to customize this would be to define a number of keymaps, e.g.

legacy-emacs-follow-link-keymap   [mouse-2] -> [follow-link]
browser-follow-link-keymap        [mouse-1] -> [follow-link]

And then a customizable variable follow-link-keymap which is
a choice between the above keymaps:

(defcustom follow-link-keymap 'browser-follow-link-keymap
  ...)

The link keymaps will then set the parent keymap to the
symbol value of follow-link-keymap.


This approach does not allow use to use double clicks on a link,
as the first click follows the link -- but that's ok I guess.

One question remains:  How do you set point in a link ?


I'll look into this approach and see what it takes.  For starters,
it should cover:

link widgets
help buttons
apropos links
info links
url links

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31 23:39               ` Kim F. Storm
@ 2004-11-01  0:33                 ` Stefan
  0 siblings, 0 replies; 28+ messages in thread
From: Stefan @ 2004-11-01  0:33 UTC (permalink / raw)
  Cc: Luc Teirlinck, emacs-devel

> And then a customizable variable follow-link-keymap which is
> a choice between the above keymaps:

> (defcustom follow-link-keymap 'browser-follow-link-keymap
>   ...)

> The link keymaps will then set the parent keymap to the
> symbol value of follow-link-keymap.

I hope you mean what you wrote in the code (the custom selects between
various symbols) and not what you wrote in the text (the custom selects
between various keymaps).

> This approach does not allow use to use double clicks on a link,
> as the first click follows the link -- but that's ok I guess.
> One question remains:  How do you set point in a link ?

Those two are pretty serious, tho.  The beauty of your original patch is
that by hooking into mouse-set-point it inherits all the code that
distinguishes between drag and no-drag.


        Stefan

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

* Re: [PATCH] mouse-1 click follows link
  2004-10-31  0:09     ` Luc Teirlinck
  2004-10-31 12:49       ` Kim F. Storm
@ 2004-11-01  7:24       ` Richard Stallman
  1 sibling, 0 replies; 28+ messages in thread
From: Richard Stallman @ 2004-11-01  7:24 UTC (permalink / raw)
  Cc: emacs-devel, storm

Can you find a few examples of code in Emacs where mapping mouse 2
to mouse 1 would be really wrong?  Let's see what sort of problems
we would have.

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

* [NEW PATCH] mouse-1 click follows link
  2004-10-31 12:53       ` Kim F. Storm
  2004-10-31 15:24         ` Luc Teirlinck
@ 2004-11-27  0:44         ` Kim F. Storm
       [not found]           ` <E1CYJ5T-0002qS-UR@fencepost.gnu.org>
  1 sibling, 1 reply; 28+ messages in thread
From: Kim F. Storm @ 2004-11-27  0:44 UTC (permalink / raw)


storm@cua.dk (Kim F. Storm) writes:

> Luc Teirlinck <teirllm@dms.auburn.edu> writes:
>
>> As I already said, I believe that there _must_ be substantially better
>> ways to give users the option to have web browser style bindings for
>> true links than the one you proposed.

Ok, here is a different approach, which does not blindly map mouse-1
to mouse-2, but requires explicit marking of "hyper links".

In the patch below, the changes to mouse.el, help.el and tooltip.el
are mostly identical to the previous set of patches, but with this
approch there are additional (small) patches to a few other lisp
packages to properly mark the hyper links in different modes.

I'm convinced that the new approach is superior to the old approach --
as it is still almost the same size and complexity, but there are no
longer any 'surprises' due to 'blind guessing'. (I had a few of those
myself with the old approach).  There may be links that doesn't work
(yet), but they should be trivial to fix.


At its base, the new approach still hooks into mouse-drag-region as
the old patch, but it now uses a mouse-on-link-p function which looks
for an explicit 'follow-link' property or key binding at the point
where you click mouse-1:

 (defun mouse-on-link-p (pos)
   (or (get-char-property pos 'follow-link)
       (save-excursion
	(goto-char pos)
	(let ((b (key-binding [follow-link] t t)))
	  (cond
	   ((eq b 'mouse-face) (get-char-property pos 'mouse-face))
	   ((functionp b) (funcall b pos))
	   (t b))))))
 
It identifies a link at POS in the current buffer by several methods,
as there is no single method which works for all modes:

1) If there is a non-nil 'follow-link' property at POS

2) If there is a key binding for [follow-link] at POS, and

  2a) the binding is 'mouse-face' and there is a mouse-face property
      at POS, or

  2b) the binding is a function F, and (F POS) returns non-nil, or

  2c) the binding is anythings else but nil.

If the return value from mouse-on-link-p is a vector or string, the
mouse-1 up event is mapped into the first character/event in the
sequence -- otherwise, mouse-1 is mapped to mouse-2.

Specifically, it returns the value of the property for 1 and 2a, the
return value from F in 2b, and the key binding in 2c.


Buttons and similar links will typically use (1).

If a mode uses mouse-face for all links in a buffer, and all mouse-face
indicates links, it can simply put a binding [follow-link] -> mouse-face
into its local keymap.  (2a)

If a mode uses mouse-face for some links, but also for other stuff, it
can use a binding [follow-link] -> FUNC in its local keymap, where
FUNC is a function that tests whether there is a link at POS.  See
the example for pcvs-defs.el below to make clicking on the file name
open that file, but not when clicking on the 'status' of a file.  (2b)

If the binding for mouse-2 works everywhere in a buffer (and uses other
means to determine what to do), a mode may bind [follow-link] -> t to
let mouse-1 do what mouse-2 does  (2c).


To simplify things, button definitions may now have a follow-link
attribute, and widget definitions may have a :follow-link attribute,
both of which maps into a follow-link property on the relevant overlay
or text.

As you can see, I have found some "buttons" and modes where I think
the mouse-1 click should follow links, but there may be more...



Index: mouse.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/mouse.el,v
retrieving revision 1.257
diff -c -r1.257 mouse.el
*** mouse.el	13 Nov 2004 01:29:45 -0000	1.257
--- mouse.el	27 Nov 2004 00:03:39 -0000
***************
*** 49,54 ****
--- 49,78 ----
    :version "21.4"
    :group 'mouse)
  
+ (defcustom mouse-1-click-follows-link 350
+   "Non-nil means that clicking mouse-1 on a link follows the link.
+ This is only done for links which have the mouse-face property.
+ 
+ If value is the symbol double, a double click follows the link.
+ 
+ If value is an integer, the time elapsed between pressing and
+ releasing the mouse button determines whether to follow the link
+ or perform the normal mouse-1 action (typically set point).
+ The absolute numeric value specifices the maximum duration of a
+ \"short click\" in milliseconds.  A positive value means that a
+ short click follows the link, and a longer click performs the
+ normal action.  A negative value gives the opposite behaviour.
+ 
+ Otherwise, a single mouse-1 click unconditionally follows the link.
+ 
+ Note that dragging the mouse never follows the link."
+   :version "21.4"
+   :type '(choice (const :tag "Disabled" nil)
+ 		 (const :tag "Double click" double)
+                  (number :tag "Single click time limit" :value 350)
+                  (other :tag "Single click" t))
+   :group 'mouse)
+ 
  \f
  ;; Provide a mode-specific menu on a mouse button.
  
***************
*** 733,738 ****
--- 757,772 ----
        (run-hooks 'mouse-leave-buffer-hook)
        (mouse-drag-region-1 start-event))))
  
+ (defun mouse-on-link-p (pos)
+   (or (get-char-property pos 'follow-link)
+       (save-excursion
+ 	(goto-char pos)
+ 	(let ((b (key-binding [follow-link] t t)))
+ 	  (cond
+ 	   ((eq b 'mouse-face) (get-char-property pos 'mouse-face))
+ 	   ((functionp b) (funcall b pos))
+ 	   (t b))))))
+ 
  (defun mouse-drag-region-1 (start-event)
    (mouse-minibuffer-check start-event)
    (let* ((echo-keystrokes 0)
***************
*** 749,754 ****
--- 783,789 ----
  		     (nth 3 bounds)
  		   ;; Don't count the mode line.
  		   (1- (nth 3 bounds))))
+ 	 on-link remap-double-click
  	 (click-count (1- (event-click-count start-event))))
      (setq mouse-selection-click-count click-count)
      (setq mouse-selection-click-count-buffer (current-buffer))
***************
*** 758,763 ****
--- 793,805 ----
      (if (< (point) start-point)
  	(goto-char start-point))
      (setq start-point (point))
+     (setq on-link (and mouse-1-click-follows-link
+ 		       (mouse-on-link-p start-point)))
+     (setq remap-double-click (and on-link
+ 				  (eq mouse-1-click-follows-link 'double)
+ 				  (= click-count 1)))
+     (if remap-double-click  ;; Don't expand mouse overlay in links
+ 	(setq click-count 0))
      (let ((range (mouse-start-end start-point start-point click-count)))
        (move-overlay mouse-drag-overlay (car range) (nth 1 range)
  		    (window-buffer start-window))
***************
*** 880,885 ****
--- 922,949 ----
  			 (or end-point
  			     (= (window-start start-window)
  				start-window-start)))
+ 		(if (and on-link
+ 			 (not end-point)
+ 			 (consp event)
+ 			 (or remap-double-click
+ 			     (and
+ 			      (not (eq mouse-1-click-follows-link 'double))
+ 			      (= click-count 0)
+ 			      (= (event-click-count event) 1)
+ 			      (not (input-pending-p))
+ 			      (or (not (integerp mouse-1-click-follows-link))
+ 				  (let ((t0 (posn-timestamp (event-start start-event)))
+ 					(t1 (posn-timestamp (event-end event))))
+ 				    (and (integerp t0) (integerp t1)
+ 					 (if (> mouse-1-click-follows-link 0)
+ 					     (<= (- t1 t0) mouse-1-click-follows-link)
+ 					   (< (- t0 t1) mouse-1-click-follows-link)))))
+ 			      (or (not double-click-time)
+ 				  (sit-for 0 (if (integerp double-click-time)
+ 						 double-click-time 500) t)))))
+ 		    (if (or (vectorp on-link) (stringp on-link))
+ 			(setq event (aref on-link 0))
+ 		      (setcar event 'mouse-2)))
  		(setq unread-command-events
  		      (cons event unread-command-events)))))
  	(delete-overlay mouse-drag-overlay)))))
Index: help.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help.el,v
retrieving revision 1.271
diff -c -r1.271 help.el
*** help.el	30 Oct 2004 01:07:20 -0000	1.271
--- help.el	27 Nov 2004 00:12:10 -0000
***************
*** 609,625 ****
  	    (princ "\n   which is ")
  	    (describe-function-1 defn)
  	    (when up-event
! 	      (let ((defn (or (string-key-binding up-event) (key-binding up-event))))
  		(unless (or (null defn) (integerp defn) (equal defn 'undefined))
! 		  (princ "\n\n-------------- up event ---------------\n\n")
! 		  (princ (key-description up-event))
  		  (if (windowp window)
  		      (princ " at that spot"))
  		  (princ " runs the command ")
  		  (prin1 defn)
  		  (princ "\n   which is ")
! 		  (describe-function-1 defn))))
! 	    (print-help-return-message)))))))
  
  \f
  (defun describe-mode (&optional buffer)
--- 609,666 ----
  	    (princ "\n   which is ")
  	    (describe-function-1 defn)
  	    (when up-event
! 	      (let ((ev (aref up-event 0))
! 		    (descr (key-description up-event))
! 		    (hdr "\n\n-------------- up event ---------------\n\n")
! 		    defn
! 		    mouse-1-tricky mouse-1-remapped)
! 		(when (and (consp ev)
! 			   (eq (car ev) 'mouse-1)
! 			   (windowp window)
! 			   mouse-1-click-follows-link
! 			   (not (eq mouse-1-click-follows-link 'double))
! 			   (with-current-buffer (window-buffer window)
! 			     (mouse-on-link-p (posn-point (event-start ev)))))
! 		  (setq mouse-1-tricky (integerp mouse-1-click-follows-link)
! 			mouse-1-remapped (or (not mouse-1-tricky)
! 					     (> mouse-1-click-follows-link 0)))
! 		  (if mouse-1-remapped
! 		      (setcar ev 'mouse-2)))
! 		(setq defn (or (string-key-binding up-event) (key-binding up-event)))
  		(unless (or (null defn) (integerp defn) (equal defn 'undefined))
! 		  (princ (if mouse-1-tricky
! 			     "\n\n----------------- up-event (short click) ----------------\n\n"
! 			   hdr))
! 		  (setq hdr nil)
! 		  (princ descr)
  		  (if (windowp window)
  		      (princ " at that spot"))
+ 		  (if mouse-1-remapped
+ 		      (princ " is remapped to <mouse-2>\n  which" ))
  		  (princ " runs the command ")
  		  (prin1 defn)
  		  (princ "\n   which is ")
! 		  (describe-function-1 defn))
! 		(when mouse-1-tricky
! 		  (setcar ev
! 			  (if (> mouse-1-click-follows-link 0) 'mouse-1 'mouse-2))
! 		  (setq defn (or (string-key-binding up-event) (key-binding up-event)))
! 		  (unless (or (null defn) (integerp defn) (equal defn 'undefined))
! 		    (princ (or hdr
! 			       "\n\n----------------- up-event (long click) ----------------\n\n"))
! 		    (princ "Pressing ")
! 		    (princ descr)
! 		    (if (windowp window)
! 			(princ " at that spot"))
! 		    (princ (format " for longer than %d milli-seconds\n"
! 				   (abs mouse-1-click-follows-link)))
! 		    (if (not mouse-1-remapped)
! 			(princ " remaps it to <mouse-2> which" ))
! 		    (princ " runs the command ")
! 		    (prin1 defn)
! 		    (princ "\n   which is ")
! 		    (describe-function-1 defn))))
! 	    (print-help-return-message))))))))
  
  \f
  (defun describe-mode (&optional buffer)
***************
*** 692,697 ****
--- 733,739 ----
  		(princ "  ")
  		(insert-button pretty-minor-mode
  			       'action (car help-button-cache)
+ 			       'follow-link t
  			       'help-echo "mouse-2, RET: show full information")
  		(princ (format " minor mode (%s):\n"
  			       (if indicator
Index: tooltip.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/tooltip.el,v
retrieving revision 1.38
diff -c -r1.38 tooltip.el
*** tooltip.el	25 Nov 2004 02:55:37 -0000	1.38
--- tooltip.el	27 Nov 2004 00:12:10 -0000
***************
*** 476,482 ****
  (defun tooltip-show-help-function (msg)
    "Function installed as `show-help-function'.
  MSG is either a help string to display, or nil to cancel the display."
!   (let ((previous-help tooltip-help-message))
      (setq tooltip-help-message msg)
      (cond ((null msg)
  	   ;; Cancel display.  This also cancels a delayed tip, if
--- 477,501 ----
  (defun tooltip-show-help-function (msg)
    "Function installed as `show-help-function'.
  MSG is either a help string to display, or nil to cancel the display."
!   (let ((previous-help tooltip-help-message)
! 	mp pos)
!     (if (and mouse-1-click-follows-link
! 	     (stringp msg)
! 	     (save-match-data
! 	       (string-match "^mouse-2" msg))
! 	     (setq mp (mouse-pixel-position))
! 	     (consp (setq pos (cdr mp)))
! 	     (setq pos (posn-at-x-y (car pos) (cdr pos) (car mp)))
! 	     (windowp (posn-window pos)))
! 	(with-current-buffer (window-buffer (posn-window pos))
! 	  (if (mouse-on-link-p (posn-point pos))
! 	      (setq msg (concat
! 		    (cond
! 		     ((eq mouse-1-click-follows-link 'double) "double-")
! 		     ((and (integerp mouse-1-click-follows-link)
! 			   (< mouse-1-click-follows-link 0)) "Long ")
! 		     (t ""))
! 		    "mouse-1" (substring msg 7))))))
      (setq tooltip-help-message msg)
      (cond ((null msg)
  	   ;; Cancel display.  This also cancels a delayed tip, if
Index: apropos.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/apropos.el,v
retrieving revision 1.98
diff -c -r1.98 apropos.el
*** apropos.el	27 Oct 2004 17:46:33 -0000	1.98
--- apropos.el	27 Nov 2004 00:03:39 -0000
***************
*** 163,168 ****
--- 163,169 ----
  (define-button-type 'apropos-symbol
    'face apropos-symbol-face
    'help-echo "mouse-2, RET: Display more help on this symbol"
+   'follow-link t
    'action #'apropos-symbol-button-display-help
    'skip t)
  
***************
*** 174,192 ****
  
  (define-button-type 'apropos-function
    'apropos-label "Function"
    'action (lambda (button)
! 	    (describe-function (button-get button 'apropos-symbol)))
!   'help-echo "mouse-2, RET: Display more help on this function")
  (define-button-type 'apropos-macro
    'apropos-label "Macro"
    'action (lambda (button)
! 	    (describe-function (button-get button 'apropos-symbol)))
!   'help-echo "mouse-2, RET: Display more help on this macro")
  (define-button-type 'apropos-command
    'apropos-label "Command"
    'action (lambda (button)
! 	    (describe-function (button-get button 'apropos-symbol)))
!   'help-echo "mouse-2, RET: Display more help on this command")
  
  ;; We used to use `customize-variable-other-window' instead for a
  ;; customizable variable, but that is slow.  It is better to show an
--- 175,198 ----
  
  (define-button-type 'apropos-function
    'apropos-label "Function"
+   'help-echo "mouse-2, RET: Display more help on this function"
+   'follow-link t
    'action (lambda (button)
! 	    (describe-function (button-get button 'apropos-symbol))))
! 
  (define-button-type 'apropos-macro
    'apropos-label "Macro"
+   'help-echo "mouse-2, RET: Display more help on this macro"
+   'follow-link t
    'action (lambda (button)
! 	    (describe-function (button-get button 'apropos-symbol))))
! 
  (define-button-type 'apropos-command
    'apropos-label "Command"
+   'help-echo "mouse-2, RET: Display more help on this command"
+   'follow-link t
    'action (lambda (button)
! 	    (describe-function (button-get button 'apropos-symbol))))
  
  ;; We used to use `customize-variable-other-window' instead for a
  ;; customizable variable, but that is slow.  It is better to show an
***************
*** 196,213 ****
--- 202,222 ----
  (define-button-type 'apropos-variable
    'apropos-label "Variable"
    'help-echo "mouse-2, RET: Display more help on this variable"
+   'follow-link t
    'action (lambda (button)
  	    (describe-variable (button-get button 'apropos-symbol))))
  
  (define-button-type 'apropos-face
    'apropos-label "Face"
    'help-echo "mouse-2, RET: Display more help on this face"
+   'follow-link t
    'action (lambda (button)
  	    (describe-face (button-get button 'apropos-symbol))))
  
  (define-button-type 'apropos-group
    'apropos-label "Group"
    'help-echo "mouse-2, RET: Display more help on this group"
+   'follow-link t
    'action (lambda (button)
  	    (customize-group-other-window
  	     (button-get button 'apropos-symbol))))
***************
*** 215,226 ****
--- 224,237 ----
  (define-button-type 'apropos-widget
    'apropos-label "Widget"
    'help-echo "mouse-2, RET: Display more help on this widget"
+   'follow-link t
    'action (lambda (button)
  	    (widget-browse-other-window (button-get button 'apropos-symbol))))
  
  (define-button-type 'apropos-plist
    'apropos-label "Plist"
    'help-echo "mouse-2, RET: Display more help on this plist"
+   'follow-link t
    'action (lambda (button)
  	    (apropos-describe-plist (button-get button 'apropos-symbol))))
  
Index: help-fns.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help-fns.el,v
retrieving revision 1.58
diff -c -r1.58 help-fns.el
*** help-fns.el	9 Nov 2004 08:20:44 -0000	1.58
--- help-fns.el	27 Nov 2004 00:03:39 -0000
***************
*** 564,569 ****
--- 564,570 ----
  		  (insert " value is shown ")
  		  (insert-button "below"
  				 'action help-button-cache
+ 				 'follow-link t
  				 'help-echo "mouse-2, RET: show value")
  		  (insert ".\n\n")))
  	      ;; Add a note for variables that have been make-var-buffer-local.
Index: help-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help-mode.el,v
retrieving revision 1.29
diff -c -r1.29 help-mode.el
*** help-mode.el	1 Aug 2004 05:53:50 -0000	1.29
--- help-mode.el	27 Nov 2004 00:03:40 -0000
***************
*** 68,73 ****
--- 68,74 ----
  ;; Button types used by help
  
  (define-button-type 'help-xref
+   'follow-link t
    'action #'help-button-action)
  
  (defun help-button-action (button)
Index: pcvs-defs.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/pcvs-defs.el,v
retrieving revision 1.29
diff -c -r1.29 pcvs-defs.el
*** pcvs-defs.el	15 Oct 2004 23:35:58 -0000	1.29
--- pcvs-defs.el	27 Nov 2004 00:03:40 -0000
***************
*** 380,385 ****
--- 380,387 ----
      ("+" .	cvs-mode-tree)
      ;; mouse bindings
      ([mouse-2] . cvs-mode-find-file)
+     ([follow-link] . (lambda (pos)
+ 		       (if (eq (get-char-property pos 'face) 'cvs-filename-face) t)))
      ([(down-mouse-3)] . cvs-menu)
      ;; dired-like bindings
      ("\C-o" .   cvs-mode-display-file)
Index: wid-edit.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/wid-edit.el,v
retrieving revision 1.130
diff -c -r1.130 wid-edit.el
*** wid-edit.el	8 Aug 2004 19:35:15 -0000	1.130
--- wid-edit.el	27 Nov 2004 00:03:40 -0000
***************
*** 327,332 ****
--- 327,333 ----
    (let ((keymap (widget-get widget :keymap))
  	(face (or (widget-get widget :value-face) 'widget-field-face))
  	(help-echo (widget-get widget :help-echo))
+ 	(follow-link (widget-get widget :follow-link))
  	(rear-sticky
  	 (or (not widget-field-add-space) (widget-get widget :size))))
      (if (functionp help-echo)
***************
*** 343,348 ****
--- 344,350 ----
  	;; works in the field when, say, Custom uses `suppress-keymap'.
  	(overlay-put overlay 'local-map keymap)
  	(overlay-put overlay 'face face)
+ 	(overlay-put overlay 'follow-link follow-link)
  	(overlay-put overlay 'help-echo help-echo))
        (setq to (1- to))
        (setq rear-sticky t))
***************
*** 352,357 ****
--- 354,360 ----
        (overlay-put overlay 'field widget)
        (overlay-put overlay 'local-map keymap)
        (overlay-put overlay 'face face)
+       (overlay-put overlay 'follow-link follow-link)
        (overlay-put overlay 'help-echo help-echo)))
    (widget-specify-secret widget))
  
***************
*** 376,381 ****
--- 379,385 ----
  (defun widget-specify-button (widget from to)
    "Specify button for WIDGET between FROM and TO."
    (let ((overlay (make-overlay from to nil t nil))
+ 	(follow-link (widget-get widget :follow-link))
  	(help-echo (widget-get widget :help-echo)))
      (widget-put widget :button-overlay overlay)
      (if (functionp help-echo)
***************
*** 387,392 ****
--- 391,397 ----
      (unless (widget-get widget :suppress-face)
        (overlay-put overlay 'face (widget-apply widget :button-face-get)))
      (overlay-put overlay 'pointer 'hand)
+     (overlay-put overlay 'follow-link follow-link)
      (overlay-put overlay 'help-echo help-echo)))
  
  (defun widget-mouse-help (window overlay point)
***************
*** 1694,1699 ****
--- 1699,1705 ----
    "An embedded link."
    :button-prefix 'widget-link-prefix
    :button-suffix 'widget-link-suffix
+   :follow-link "\C-m"
    :help-echo "Follow the link."
    :format "%[%t%]")
  
Index: gnus/gnus-group.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/gnus/gnus-group.el,v
retrieving revision 1.31
diff -c -r1.31 gnus-group.el
*** gnus/gnus-group.el	29 Oct 2004 02:23:24 -0000	1.31
--- gnus/gnus-group.el	27 Nov 2004 00:03:41 -0000
***************
*** 591,596 ****
--- 591,597 ----
    "\M-e" gnus-group-edit-group-method
    "^" gnus-group-enter-server-mode
    gnus-mouse-2 gnus-mouse-pick-group
+   [follow-link] mouse-face
    "<" beginning-of-buffer
    ">" end-of-buffer
    "\C-c\C-b" gnus-bug
Index: gnus/gnus-sum.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/gnus/gnus-sum.el,v
retrieving revision 1.54
diff -c -r1.54 gnus-sum.el
*** gnus/gnus-sum.el	22 Nov 2004 20:24:59 -0000	1.54
--- gnus/gnus-sum.el	27 Nov 2004 00:03:42 -0000
***************
*** 1703,1708 ****
--- 1703,1709 ----
    "Q" gnus-summary-exit-no-update
    "\C-c\C-i" gnus-info-find-node
    gnus-mouse-2 gnus-mouse-pick-article
+   [follow-link] mouse-face
    "m" gnus-summary-mail-other-window
    "a" gnus-summary-post-news
    "i" gnus-summary-news-other-window

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [NEW PATCH] mouse-1 click follows link
       [not found]           ` <E1CYJ5T-0002qS-UR@fencepost.gnu.org>
@ 2004-12-14 15:15             ` Kim F. Storm
  2004-12-14 20:13               ` Robert J. Chassell
  2004-12-16 12:24               ` Richard Stallman
  0 siblings, 2 replies; 28+ messages in thread
From: Kim F. Storm @ 2004-12-14 15:15 UTC (permalink / raw)
  Cc: rms

Richard Stallman <rms@gnu.org> writes:

>     + (defcustom mouse-1-click-follows-link 350
>     +   "Non-nil means that clicking mouse-1 on a link follows the link.
>     + This is only done for links which have the mouse-face property.
>
> That's not true any more, with the rest of your design, right?

True.  I didn't fix the doc string.

>
>     + If value is the symbol double, a double click follows the link.
>
> That should say `double'.  Or should it be :double?

It is `double'.

>
>
> Aren't there more kinds of links that need to support this?
> For instance, what about Compilation mode and Dired.

Right -- there are more places that need to be adapted, but I'm
sure that if I check these changes into CVS, that will quickly
be spotted and fixed.

In most cases, it will be as trivial as for dired and compile
as illustrated below:

Should I install these changes (with proper doc string)?


On question is how to document this in the manuals.

Of course, the Lisp ref should explain that mouse-2 is the preferred
binding for "following links", but then in details explain how to make
mouse-1 automatically follow mouse-2 links.

But what about the Emacs manual? Would a it suffice to put a generic
mentioning like this somewhere (I would add this to NEWS as well):

** A mouse-1 click now follows links 

  For historical reasons, Emacs uses mouse-2 to take action on
clickable text in a buffer, typically to follow a link to a position
in another file or buffer.  In most cases, clicking mouse-1 now also
follows a link; the exception being modes where mouse-1 has a
different binding on clickable text, or the mouse-2 action is
something more involved than just following a link.

  If you want to set the cursor in the middle of a link, rather than
following the link, just hold down the mouse-1 button for half a
second or more before releasing it.

  You can modify this behaviour by customizing the variable
`mouse-1-click-follows-link'.


*** dired.el	22 Nov 2004 22:01:22 +0100	1.298
--- dired.el	30 Nov 2004 01:12:12 +0100	
***************
*** 1104,1109 ****
--- 1104,1110 ----
    (let ((map (make-keymap)))
      (suppress-keymap map)
      (define-key map [mouse-2] 'dired-mouse-find-file-other-window)
+     (define-key map [follow-link] 'mouse-face)
      ;; Commands to mark or flag certain categories of files
      (define-key map "#" 'dired-flag-auto-save-files)
      (define-key map "." 'dired-clean-directory)

*** compile.el	25 Nov 2004 11:21:11 +0100	1.342
--- compile.el	14 Dec 2004 15:50:34 +0100	
***************
*** 1044,1049 ****
--- 1044,1050 ----
  (defvar compilation-minor-mode-map
    (let ((map (make-sparse-keymap)))
      (define-key map [mouse-2] 'compile-goto-error)
+     (define-key map [follow-link] 'mouse-face)
      (define-key map "\C-c\C-c" 'compile-goto-error)
      (define-key map "\C-m" 'compile-goto-error)
      (define-key map "\C-c\C-k" 'kill-compilation)
***************
*** 1073,1078 ****
--- 1074,1080 ----
  (defvar compilation-button-map
    (let ((map (make-sparse-keymap)))
      (define-key map [mouse-2] 'compile-goto-error)
+     (define-key map [follow-link] 'mouse-face)
      (define-key map "\C-m" 'compile-goto-error)
      map)
    "Keymap for compilation-message buttons.")
***************
*** 1084,1089 ****
--- 1086,1092 ----
      ;; because that introduces a menu bar item we don't want.
      ;; That confuses C-down-mouse-3.
      (define-key map [mouse-2] 'compile-goto-error)
+     (define-key map [follow-link] 'mouse-face)
      (define-key map "\C-c\C-c" 'compile-goto-error)
      (define-key map "\C-m" 'compile-goto-error)
      (define-key map "\C-c\C-k" 'kill-compilation)


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-14 15:15             ` Kim F. Storm
@ 2004-12-14 20:13               ` Robert J. Chassell
  2004-12-14 23:33                 ` Kim F. Storm
  2004-12-15  8:46                 ` Richard Stallman
  2004-12-16 12:24               ` Richard Stallman
  1 sibling, 2 replies; 28+ messages in thread
From: Robert J. Chassell @ 2004-12-14 20:13 UTC (permalink / raw)
  Cc: rms, emacs-devel

    ** A mouse-1 click now follows links 

      For historical reasons, Emacs uses mouse-2 to take action on
    clickable text in a buffer ...

Please explain why.  The main reason was good -- the Emacs pattern
very much followed those human interface guidelines which say to make
the most common actions easy.

To me, the use of mouse-1 to follow links is odd, since I mainly use
it to set point, and I do that far more often than follow links.

I am not saying that you should not change the pattern, but that it is
worth remembering that the prime reason is more than historical
accident.

-- 
    Robert J. Chassell                         
    bob@rattlesnake.com                         GnuPG Key ID: 004B4AC8
    http://www.rattlesnake.com                  http://www.teak.cc

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-14 20:13               ` Robert J. Chassell
@ 2004-12-14 23:33                 ` Kim F. Storm
  2004-12-16 23:08                   ` Kevin Rodgers
  2004-12-15  8:46                 ` Richard Stallman
  1 sibling, 1 reply; 28+ messages in thread
From: Kim F. Storm @ 2004-12-14 23:33 UTC (permalink / raw)
  Cc: rms, emacs-devel

"Robert J. Chassell" <bob@rattlesnake.com> writes:

>     ** A mouse-1 click now follows links 
>
>       For historical reasons, Emacs uses mouse-2 to take action on
>     clickable text in a buffer ...
>
> Please explain why.  The main reason was good -- the Emacs pattern
> very much followed those human interface guidelines which say to make
> the most common actions easy.

I say "historically" because most other "modern" GUI uses mouse-1 to
BOTH set point (when not over a link) and follow a link (when over a link).

So the change is aimed at simplifying the transition for users who
come from other platforms.

>
> To me, the use of mouse-1 to follow links is odd, since I mainly use
> it to set point, and I do that far more often than follow links.

How often do you set point in a link ?

>
> I am not saying that you should not change the pattern, but that it is
> worth remembering that the prime reason is more than historical
> accident.

We should remember that, but it is not necessary to mention it in this
context.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-14 20:13               ` Robert J. Chassell
  2004-12-14 23:33                 ` Kim F. Storm
@ 2004-12-15  8:46                 ` Richard Stallman
  1 sibling, 0 replies; 28+ messages in thread
From: Richard Stallman @ 2004-12-15  8:46 UTC (permalink / raw)
  Cc: emacs-devel, storm

    To me, the use of mouse-1 to follow links is odd, since I mainly use
    it to set point, and I do that far more often than follow links.

The purpose of this change is compatibility with most other programs.
Beginning users are accustomed to using Mouse-1 to follow links.

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-14 15:15             ` Kim F. Storm
  2004-12-14 20:13               ` Robert J. Chassell
@ 2004-12-16 12:24               ` Richard Stallman
  2004-12-16 15:12                 ` Kim F. Storm
  2004-12-17 15:48                 ` Kim F. Storm
  1 sibling, 2 replies; 28+ messages in thread
From: Richard Stallman @ 2004-12-16 12:24 UTC (permalink / raw)
  Cc: emacs-devel

    Should I install these changes (with proper doc string)?

Yes, please do.

      For historical reasons, Emacs uses mouse-2 to take action on
    clickable text in a buffer, typically to follow a link to a position
    in another file or buffer.

It is not just historical reasons.  Mouse-2 fits in better with the
usual Emacs mouse bindings than Mouse-1.  We've decided to give higher
priority to compatibility with other programs, at the cost of fitting
in not quite as well.

    But what about the Emacs manual? Would a it suffice to put a generic
    mentioning like this somewhere (I would add this to NEWS as well):

I suggest you grep for Mouse-2 and for Mouse-1, and change the places
that need changing.

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-16 12:24               ` Richard Stallman
@ 2004-12-16 15:12                 ` Kim F. Storm
  2004-12-18  0:20                   ` Richard Stallman
  2004-12-17 15:48                 ` Kim F. Storm
  1 sibling, 1 reply; 28+ messages in thread
From: Kim F. Storm @ 2004-12-16 15:12 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     Should I install these changes (with proper doc string)?
>
> Yes, please do.
>
>       For historical reasons, Emacs uses mouse-2 to take action on
>     clickable text in a buffer, typically to follow a link to a position
>     in another file or buffer.
>
> It is not just historical reasons.  Mouse-2 fits in better with the
> usual Emacs mouse bindings than Mouse-1.  We've decided to give higher
> priority to compatibility with other programs, at the cost of fitting
> in not quite as well.

Should I mention that in the manual?

>
>     But what about the Emacs manual? Would a it suffice to put a generic
>     mentioning like this somewhere (I would add this to NEWS as well):
>
> I suggest you grep for Mouse-2 and for Mouse-1, and change the places
> that need changing.

What should I change them to?

Should I mention both Mouse-1 and Mouse-2?

Should I mention mouse-1-click-follows-link (every time)?

Should I mention that a long mouse-1 click still sets point
(depending on the setting of mouse-1-click-follows-link)?


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-14 23:33                 ` Kim F. Storm
@ 2004-12-16 23:08                   ` Kevin Rodgers
  2004-12-17  9:57                     ` Kim F. Storm
  2004-12-17 10:20                     ` Alex Schroeder
  0 siblings, 2 replies; 28+ messages in thread
From: Kevin Rodgers @ 2004-12-16 23:08 UTC (permalink / raw)


Kim F. Storm wrote:
> "Robert J. Chassell" <bob@rattlesnake.com> writes:
>>To me, the use of mouse-1 to follow links is odd, since I mainly use
>>it to set point, and I do that far more often than follow links.
> 
> How often do you set point in a link ?

I am very frustrated by interfaces that don't let me select (aka copy)
the link text by click-and-drag.

-- 
Kevin Rodgers

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-16 23:08                   ` Kevin Rodgers
@ 2004-12-17  9:57                     ` Kim F. Storm
  2004-12-17 10:20                     ` Alex Schroeder
  1 sibling, 0 replies; 28+ messages in thread
From: Kim F. Storm @ 2004-12-17  9:57 UTC (permalink / raw)
  Cc: emacs-devel

Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Kim F. Storm wrote:
>> "Robert J. Chassell" <bob@rattlesnake.com> writes:
>>>To me, the use of mouse-1 to follow links is odd, since I mainly use
>>>it to set point, and I do that far more often than follow links.
>> How often do you set point in a link ?
>
> I am very frustrated by interfaces that don't let me select (aka copy)
> the link text by click-and-drag.

I have the same frustration -- so with my proposed change, dragging
the mouse works as it always did, i.e.  it copies the link text.

It only follows the link if you CLICK the mouse button.

And if you really want to set point in the link, just hold the
mouse-1 button down a litte longer.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-16 23:08                   ` Kevin Rodgers
  2004-12-17  9:57                     ` Kim F. Storm
@ 2004-12-17 10:20                     ` Alex Schroeder
  1 sibling, 0 replies; 28+ messages in thread
From: Alex Schroeder @ 2004-12-17 10:20 UTC (permalink / raw)
  Cc: emacs-devel

Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Kim F. Storm wrote:
>> "Robert J. Chassell" <bob@rattlesnake.com> writes:
>>>To me, the use of mouse-1 to follow links is odd, since I mainly use
>>>it to set point, and I do that far more often than follow links.
>> How often do you set point in a link ?
>
> I am very frustrated by interfaces that don't let me select (aka copy)
> the link text by click-and-drag.

Well, it is true that I never need *part* of a link.  The usual
interfaces (eg. web browsers) make it tricky to *select* a link,
however.  This is why most of them added a context menu item saying
"copy link location" or "copy email address".  Maybe we should start
considering what kind of things we would want to add to a context
menu.

Alex.
-- 
.O.  http://www.emacswiki.org/alex/
..O  Schroeder's fifth law:
OOO  Never accept more work than you can handle in one night of hacking.

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-16 12:24               ` Richard Stallman
  2004-12-16 15:12                 ` Kim F. Storm
@ 2004-12-17 15:48                 ` Kim F. Storm
  1 sibling, 0 replies; 28+ messages in thread
From: Kim F. Storm @ 2004-12-17 15:48 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     Should I install these changes (with proper doc string)?
>
> Yes, please do.

Done.

I also added some text to NEWS -- please review.
>
>     But what about the Emacs manual? Would a it suffice to put a generic
>     mentioning like this somewhere (I would add this to NEWS as well):
>
> I suggest you grep for Mouse-2 and for Mouse-1, and change the places
> that need changing.

I will work on updating the manuals over the next few days.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-16 15:12                 ` Kim F. Storm
@ 2004-12-18  0:20                   ` Richard Stallman
  2004-12-18 13:50                     ` Robert J. Chassell
  0 siblings, 1 reply; 28+ messages in thread
From: Richard Stallman @ 2004-12-18  0:20 UTC (permalink / raw)
  Cc: emacs-devel

    > It is not just historical reasons.  Mouse-2 fits in better with the
    > usual Emacs mouse bindings than Mouse-1.  We've decided to give higher
    > priority to compatibility with other programs, at the cost of fitting
    > in not quite as well.

    Should I mention that in the manual?

There's no need for the manual to concern itself with previous
versions of Emacs except in the Antinews section.  However, explaining
briefly the motivation for what the current version does is useful
when it is interesting to the reader.  So if you see a reason/occasion
to do that, please try it.

    > I suggest you grep for Mouse-2 and for Mouse-1, and change the places
    > that need changing.

    What should I change them to?

That question has no general answer.  How to change the text depends, in
each case, on the details of the situation.

    Should I mention both Mouse-1 and Mouse-2?

Probably in most cases only Mouse-1.  But it partly depends
on what reads well and what would be interesting to the reader.

    Should I mention mouse-1-click-follows-link (every time)?

It would be boring and wasteful to repeat it in each of these places
where Mouse-1 gets a brief mention.  Rather, find one central place to
talk about this option.  Perhaps the section that explains the basic
general mouse commands could also talk about the convention for mouse
link following and the options that affect it.

    Should I mention that a long mouse-1 click still sets point
    (depending on the setting of mouse-1-click-follows-link)?

Try to put that in the one general explanation and see if it works.

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

* Re: [NEW PATCH] mouse-1 click follows link
  2004-12-18  0:20                   ` Richard Stallman
@ 2004-12-18 13:50                     ` Robert J. Chassell
  0 siblings, 0 replies; 28+ messages in thread
From: Robert J. Chassell @ 2004-12-18 13:50 UTC (permalink / raw)


When you write new documentation for `mouse-1 click follows link',
please remember to tell people about

    Mouse-1  between the first character of a link and the previous,
    Mouse-3  between the last character of a link and the next,
and Mouse-3  to paste the link

i.e., 
        mouse-set-point
        mouse-save-then-kill
        mouse-yank-at-click

This is long established and useful since it works when a drag tends
to bring in extranous characters.  And copying links is common.

As far as I can see, a problem sometimes occurs when people are
confused by the position of point: with some cursors, novices think it
is `on' a character rather than before it.

In particular, people are occasionally confused by a `box' cursor
shape that looks as if they are putting point `on the character'
rather than between that character and the previous character.

(After you learn what a `box' signifies, it becomes a good text cursor
since it remains visible, but not irritating so long as it does not
blink.  On the other hand, a `bar' does not have the positioning
problem, but is less visible unless it blinks, in which case, it
becomes too visible for many.  Setting a non-blinking bar cursor to
another color fails on a black and white display, so that is not an
option.  As far as I can see, good documentation is the best
solution.)

Thank you.

--
    Robert J. Chassell
    bob@rattlesnake.com                         GnuPG Key ID: 004B4AC8
    http://www.rattlesnake.com                  http://www.teak.cc

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

end of thread, other threads:[~2004-12-18 13:50 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-29 13:04 [PATCH] mouse-1 click follows link Kim F. Storm
2004-10-29 23:54 ` Luc Teirlinck
2004-10-30 22:04   ` Kim F. Storm
2004-10-31  0:09     ` Luc Teirlinck
2004-10-31 12:49       ` Kim F. Storm
2004-11-01  7:24       ` Richard Stallman
2004-10-31  0:34     ` Luc Teirlinck
2004-10-31 12:53       ` Kim F. Storm
2004-10-31 15:24         ` Luc Teirlinck
2004-10-31 18:37           ` David Kastrup
2004-10-31 20:03             ` Luc Teirlinck
2004-10-31 20:13               ` David Kastrup
2004-10-31 21:40             ` Stefan
2004-10-31 23:39               ` Kim F. Storm
2004-11-01  0:33                 ` Stefan
2004-11-27  0:44         ` [NEW PATCH] " Kim F. Storm
     [not found]           ` <E1CYJ5T-0002qS-UR@fencepost.gnu.org>
2004-12-14 15:15             ` Kim F. Storm
2004-12-14 20:13               ` Robert J. Chassell
2004-12-14 23:33                 ` Kim F. Storm
2004-12-16 23:08                   ` Kevin Rodgers
2004-12-17  9:57                     ` Kim F. Storm
2004-12-17 10:20                     ` Alex Schroeder
2004-12-15  8:46                 ` Richard Stallman
2004-12-16 12:24               ` Richard Stallman
2004-12-16 15:12                 ` Kim F. Storm
2004-12-18  0:20                   ` Richard Stallman
2004-12-18 13:50                     ` Robert J. Chassell
2004-12-17 15:48                 ` Kim F. Storm

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).