changeset 107917:b8efa032f216

Put breadcrumbs on overlay instead of inserting to buffer (bug#5809). * info.el (Info-find-node-2): Comment out code that skips breadcrumbs line. (Info-mouse-follow-link): New command. (Info-link-keymap): New keymap. (Info-breadcrumbs): Rename from `Info-insert-breadcrumbs'. Return a string with links instead of inserting breadcrumbs to the Info buffer. (Info-fontify-node): Comment out code that inserts breadcrumbs. Instead of putting the `invisible' text property over the Info header, make an overlay over the Info header with the `invisible' property and `after-string' set to the string returned by `Info-breadcrumbs'.
author Juri Linkov <juri@jurta.org>
date Tue, 06 Apr 2010 01:15:04 +0300
parents a8900b7136bc
children 3859eae64644
files lisp/ChangeLog lisp/info.el
diffstat 2 files changed, 70 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Apr 05 11:46:29 2010 -0400
+++ b/lisp/ChangeLog	Tue Apr 06 01:15:04 2010 +0300
@@ -1,3 +1,20 @@
+2010-04-05  Juri Linkov  <juri@jurta.org>
+
+	Put breadcrumbs on overlay instead of inserting to buffer (bug#5809).
+
+	* info.el (Info-find-node-2): Comment out code that skips
+	breadcrumbs line.
+	(Info-mouse-follow-link): New command.
+	(Info-link-keymap): New keymap.
+	(Info-breadcrumbs): Rename from `Info-insert-breadcrumbs'.
+	Return a string with links instead of inserting breadcrumbs
+	to the Info buffer.
+	(Info-fontify-node): Comment out code that inserts breadcrumbs.
+	Instead of putting the `invisible' text property over the Info
+	header, make an overlay over the Info header with the `invisible'
+	property and `after-string' set to the string returned by
+	`Info-breadcrumbs'.
+
 2010-04-03  Chong Yidong  <cyd@stupidchicken.com>
 
 	* help.el (help-window-setup-finish): Doc fix (Bug#5830).
--- a/lisp/info.el	Mon Apr 05 11:46:29 2010 -0400
+++ b/lisp/info.el	Tue Apr 06 01:15:04 2010 +0300
@@ -1053,8 +1053,8 @@
 	    (Info-select-node)
 	    (goto-char (point-min))
 	    (forward-line 1)		       ; skip header line
-	    (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
-	      (forward-line 1))
+	    ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
+	    ;;   (forward-line 1))
 
 	    (cond (anchorpos
                    (let ((new-history (list Info-current-file
@@ -3551,6 +3551,19 @@
      ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
       (Info-goto-node node fork)))
     node))
+
+(defun Info-mouse-follow-link (click)
+  "Follow a link where you click."
+  (interactive "e")
+  (let* ((position (event-start click))
+	 (posn-string (and position (posn-string position)))
+	 (string (car-safe posn-string))
+	 (string-pos (cdr-safe posn-string))
+	 (link-args (and string string-pos
+			 (get-text-property string-pos 'link-args string))))
+    (when link-args
+      (Info-goto-node link-args))))
+
 
 (defvar Info-mode-map
   (let ((map (make-keymap)))
@@ -4141,11 +4154,22 @@
     keymap)
   "Keymap to put on the Up link in the text or the header line.")
 
-(defun Info-insert-breadcrumbs ()
+(defvar Info-link-keymap
+  (let ((keymap (make-sparse-keymap)))
+    (define-key keymap [header-line mouse-1] 'Info-mouse-follow-link)
+    (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
+    (define-key keymap [header-line down-mouse-1] 'ignore)
+    (define-key keymap [mouse-2] 'Info-mouse-follow-link)
+    (define-key keymap [follow-link] 'mouse-face)
+    keymap)
+  "Keymap to put on the link in the text or the header line.")
+
+(defun Info-breadcrumbs ()
   (let ((nodes (Info-toc-nodes Info-current-file))
 	(node Info-current-node)
         (crumbs ())
-        (depth Info-breadcrumbs-depth))
+        (depth Info-breadcrumbs-depth)
+	line)
 
     ;; Get ancestors from the cached parent-children node info
     (while (and (not (equal "Top" node)) (> depth 0))
@@ -4172,15 +4196,25 @@
 			     (file-name-nondirectory Info-current-file)
 			   ;; Some legacy code can still use a symbol.
 			   Info-current-file)))))
-	  (insert (if (bolp) "" " > ")
-		  (cond
-		   ((null node) "...")
-		   ((equal node Info-current-node)
-		    ;; No point linking to ourselves.
-		    (propertize text 'font-lock-face 'info-header-node))
-		   (t
-		    (concat "*Note " text "::"))))))
-      (insert "\n"))))
+	  (setq line (concat
+		      line
+		      (if (null line) "" " > ")
+		      (cond
+		       ((null node) "...")
+		       ((equal node Info-current-node)
+			;; No point linking to ourselves.
+			(propertize text 'font-lock-face 'info-header-node))
+		       (t
+			(propertize text
+				    'mouse-face 'highlight
+				    'font-lock-face 'info-header-xref
+				    'help-echo "mouse-2: Go to node"
+				    'keymap Info-link-keymap
+				    'link-args text)))))))
+      (setq line (concat line "\n")))
+    ;; (font-lock-append-text-property 0 (length line)
+    ;; 				    'font-lock-face 'header-line line)
+    line))
 
 (defun Info-fontify-node ()
   "Fontify the node."
@@ -4227,8 +4261,8 @@
 		((string-equal (downcase tag) "next") Info-next-link-keymap)
 		((string-equal (downcase tag) "up"  ) Info-up-link-keymap))))))
 
-        (when (> Info-breadcrumbs-depth 0)
-          (Info-insert-breadcrumbs))
+        ;; (when (> Info-breadcrumbs-depth 0)
+        ;;   (insert (Info-breadcrumbs)))
 
         ;; Treat header line.
         (when Info-use-header-line
@@ -4260,7 +4294,10 @@
             ;; that is in the header, if it is just part.
             (cond
              ((> Info-breadcrumbs-depth 0)
-              (put-text-property (point-min) (1+ header-end) 'invisible t))
+	      (let ((ov (make-overlay (point-min) (1+ header-end))))
+		(overlay-put ov 'invisible t)
+		(overlay-put ov 'after-string (Info-breadcrumbs))
+		(overlay-put ov 'evaporate t)))
              ((not (bobp))
               ;; Hide the punctuation at the end, too.
               (skip-chars-backward " \t,")