unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#14670: Highlight visited links
@ 2013-06-19 22:28 Juri Linkov
  2013-06-26 23:27 ` Juri Linkov
  0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2013-06-19 22:28 UTC (permalink / raw)
  To: 14670

Severity: wishlist
Tags: patch

Visiting a URL link from Info doesn't highlight it as visited.

I'm afraid that adding a visited URL to the existing variable
`Info-history' might break other functions that expect it containing
only visited Info nodes in the format `(FILENAME NODENAME BUFFERPOS)'.
So I created a new variable `Info-url-history':

=== modified file 'lisp/info.el'
--- lisp/info.el	2013-06-17 23:57:07 +0000
+++ lisp/info.el	2013-06-19 22:28:22 +0000
@@ -50,6 +50,9 @@ (defvar Info-history-list nil
   "List of all Info nodes user has visited.
 Each element of the list is a list (FILENAME NODENAME).")
 
+(defvar Info-url-history nil
+  "List of all URLs user has visited.")
+
 (defcustom Info-history-skip-intermediate-nodes t
   "Non-nil means don't record intermediate Info nodes to the history.
 Intermediate Info nodes are nodes visited by Info internally in the process of
@@ -3882,6 +3885,9 @@ (defun Info-try-follow-nearest-node (&op
     (cond
      ((setq node (Info-get-token (point) "[hf]t?tps?://"
 				 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
+      (when Info-fontify-visited-nodes
+	(setq Info-url-history (cons node (remove node Info-url-history)))
+	(Info-fontify-node))
       (browse-url node)
       (setq node t))
      ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
@@ -4972,11 +4978,16 @@ (defun Info-fontify-node ()
 
       ;; Fontify http and ftp references
       (goto-char (point-min))
-      (when not-fontified-p
+      (when (or not-fontified-p fontify-visited-p)
         (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
                                   nil t)
           (add-text-properties (match-beginning 0) (match-end 0)
-                               '(font-lock-face info-xref
+                               `(font-lock-face
+				 ,(if (and Info-fontify-visited-nodes
+					   (member (buffer-substring-no-properties
+						    (match-beginning 0) (match-end 0))
+						   Info-url-history))
+				      'info-xref-visited 'info-xref)
                                  mouse-face highlight
                                  help-echo "mouse-2: go to this URL"))))
 





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

* bug#14670: Highlight visited links
  2013-06-19 22:28 bug#14670: Highlight visited links Juri Linkov
@ 2013-06-26 23:27 ` Juri Linkov
  2013-06-27  2:41   ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2013-06-26 23:27 UTC (permalink / raw)
  To: 14670

This patch adds the support for links in virtual Info nodes
rendered by shr.el.  A virtual Info node function can just
call `shr-insert-document' and this patch supports the
fontification and navigation for links added by the renderer.

=== modified file 'lisp/info.el'
--- lisp/info.el	2013-05-27 22:42:11 +0000
+++ lisp/info.el	2013-06-24 22:30:15 +0000
@@ -3114,10 +3145,10 @@ (defun Info-next-reference (&optional re
 	    (old-pt (point))
 	    (case-fold-search t))
 	(or (eobp) (forward-char 1))
-	(or (Info-next-reference-or-link pat 'link)
+	(or (Info-next-reference-or-link pat 'shr-url)
 	    (progn
 	      (goto-char (point-min))
-	      (or (Info-next-reference-or-link pat 'link)
+	      (or (Info-next-reference-or-link pat 'shr-url)
 		  (progn
 		    (goto-char old-pt)
 		    (user-error "No cross references in this node")))))
@@ -3141,10 +3172,10 @@ (defun Info-prev-reference (&optional re
       (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
 	    (old-pt (point))
 	    (case-fold-search t))
-	(or (Info-prev-reference-or-link pat 'link)
+	(or (Info-prev-reference-or-link pat 'shr-url)
 	    (progn
 	      (goto-char (point-max))
-	      (or (Info-prev-reference-or-link pat 'link)
+	      (or (Info-prev-reference-or-link pat 'shr-url)
 		  (progn
 		    (goto-char old-pt)
 		    (user-error "No cross references in this node")))))
@@ -3863,6 +3919,8 @@ (defun Info-try-follow-nearest-node (&op
 If FORK is non-nil, it is passed to `Info-goto-node'."
   (let (node)
     (cond
+     ((and (setq node (get-text-property (point) 'shr-url))
+	   (not (eq node t)))
+      (Info-goto-node node fork))
      ((setq node (Info-get-token (point) "[hf]t?tps?://"
 				 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
       (browse-url node)
@@ -4701,6 +4764,18 @@ (defun Info-fontify-node ()
             (add-text-properties (1- (match-beginning 2)) (match-end 2)
                                  '(invisible t front-sticky nil rear-nonsticky t)))))
 
+      ;; Fontify links
+      (goto-char (point-min))
+      (when (or not-fontified-p fontify-visited-p)
+	(let ((beg (next-single-property-change (point-min) 'shr-url))
+	      (end nil))
+	  (while (and beg (setq end (next-single-property-change beg 'shr-url)))
+	    (add-text-properties beg end
+				 `(font-lock-face info-xref
+				   mouse-face highlight
+				   help-echo "mouse-2: go to this node"))
+	    (setq beg (next-single-property-change end 'shr-url)))))
+
       ;; Fontify cross references
       (goto-char (point-min))
       (when (or not-fontified-p fontify-visited-p)
@@ -4969,7 +5053,7 @@ (defun Info-fontify-node ()
           (while (re-search-forward "\\(([0-9]+)\\)" nil t)
             (add-text-properties (match-beginning 0) (match-end 0)
                                  `(font-lock-face info-xref
-                                   link t
+                                   shr-url t
                                    mouse-face highlight
                                    help-echo
                                    ,(if (< (point) limit)







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

* bug#14670: Highlight visited links
  2013-06-26 23:27 ` Juri Linkov
@ 2013-06-27  2:41   ` Stefan Monnier
  2013-06-27 23:35     ` Juri Linkov
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2013-06-27  2:41 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 14670

> -	(or (Info-next-reference-or-link pat 'link)
> +	(or (Info-next-reference-or-link pat 'shr-url)

Why?


        Stefan





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

* bug#14670: Highlight visited links
  2013-06-27  2:41   ` Stefan Monnier
@ 2013-06-27 23:35     ` Juri Linkov
  2016-02-24  4:56       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2013-06-27 23:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 14670

>> -	(or (Info-next-reference-or-link pat 'link)
>> +	(or (Info-next-reference-or-link pat 'shr-url)
>
> Why?

Actually there is no need to rename `link' to `shr-url' because
shr.el is flexible enough to allow arbitrary text properties for links:

  (defun info-render-node (html)
    (let ((shr-external-rendering-functions '((a . info-tag-a))))
      (shr-insert-document html)))

  (defun info-tag-a (cont)
    (let ((url (cdr (assq :href cont)))
          (start (point)))
      (shr-generic cont)
      (when url
        (add-text-properties start (point)
                             (list 'link (shr-expand-url url))))))

So without renaming link text-props, the patch to support
text-prop links in Info becomes shorter:

=== modified file 'lisp/info.el'
--- lisp/info.el	2013-06-27 09:20:04 +0000
+++ lisp/info.el	2013-06-27 23:31:27 +0000
@@ -3863,6 +3919,8 @@ (defun Info-try-follow-nearest-node (&op
 If FORK is non-nil, it is passed to `Info-goto-node'."
   (let (node)
     (cond
+     ((and (setq node (get-text-property (point) 'link)) (not (eq node t)))
+      (Info-goto-node node fork))
      ((setq node (Info-get-token (point) "[hf]t?tps?://"
 				 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
       (browse-url node)
@@ -4701,6 +4766,18 @@ (defun Info-fontify-node ()
             (add-text-properties (1- (match-beginning 2)) (match-end 2)
                                  '(invisible t front-sticky nil rear-nonsticky t)))))
 
+      ;; Fontify links
+      (goto-char (point-min))
+      (when not-fontified-p
+	(let ((beg (next-single-property-change (point-min) 'link))
+	      (end nil))
+	  (while (and beg (setq end (next-single-property-change beg 'link)))
+	    (add-text-properties beg end
+				 '(font-lock-face info-xref
+				   mouse-face highlight
+				   help-echo "mouse-2: go to this link"))
+	    (setq beg (next-single-property-change end 'link)))))
+
       ;; Fontify cross references
       (goto-char (point-min))
       (when (or not-fontified-p fontify-visited-p)






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

* bug#14670: Highlight visited links
  2013-06-27 23:35     ` Juri Linkov
@ 2016-02-24  4:56       ` Lars Ingebrigtsen
  2019-06-27 11:13         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-24  4:56 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Stefan Monnier, 14670

Juri Linkov <juri@jurta.org> writes:

> So without renaming link text-props, the patch to support
> text-prop links in Info becomes shorter:

I tried applying the patch and then going to an Info node that had an
URL, and I didn't really see any difference...  Is this patch still
applicable?

>
> === modified file 'lisp/info.el'
> --- lisp/info.el	2013-06-27 09:20:04 +0000
> +++ lisp/info.el	2013-06-27 23:31:27 +0000
> @@ -3863,6 +3919,8 @@ (defun Info-try-follow-nearest-node (&op
>  If FORK is non-nil, it is passed to `Info-goto-node'."
>    (let (node)
>      (cond
> +     ((and (setq node (get-text-property (point) 'link)) (not (eq node t)))
> +      (Info-goto-node node fork))
>       ((setq node (Info-get-token (point) "[hf]t?tps?://"
>  				 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
>        (browse-url node)
> @@ -4701,6 +4766,18 @@ (defun Info-fontify-node ()
>              (add-text-properties (1- (match-beginning 2)) (match-end 2)
>                                   '(invisible t front-sticky nil rear-nonsticky t)))))
>
> +      ;; Fontify links
> +      (goto-char (point-min))
> +      (when not-fontified-p
> +	(let ((beg (next-single-property-change (point-min) 'link))
> +	      (end nil))
> +	  (while (and beg (setq end (next-single-property-change beg 'link)))
> +	    (add-text-properties beg end
> +				 '(font-lock-face info-xref
> +				   mouse-face highlight
> +				   help-echo "mouse-2: go to this link"))
> +	    (setq beg (next-single-property-change end 'link)))))
> +
>        ;; Fontify cross references
>        (goto-char (point-min))
>        (when (or not-fontified-p fontify-visited-p)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#14670: Highlight visited links
  2016-02-24  4:56       ` Lars Ingebrigtsen
@ 2019-06-27 11:13         ` Lars Ingebrigtsen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-27 11:13 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Stefan Monnier, 14670

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Juri Linkov <juri@jurta.org> writes:
>
>> So without renaming link text-props, the patch to support
>> text-prop links in Info becomes shorter:
>
> I tried applying the patch and then going to an Info node that had an
> URL, and I didn't really see any difference...  Is this patch still
> applicable?

I asked that three years ago and got no response, so I'm closing this
bug report.  Please reopen if this is still an issue.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2019-06-27 11:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-19 22:28 bug#14670: Highlight visited links Juri Linkov
2013-06-26 23:27 ` Juri Linkov
2013-06-27  2:41   ` Stefan Monnier
2013-06-27 23:35     ` Juri Linkov
2016-02-24  4:56       ` Lars Ingebrigtsen
2019-06-27 11:13         ` Lars Ingebrigtsen

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).