unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ivan Shmakov <ivan@siamics.net>
To: 20032@debbugs.gnu.org
Subject: bug#20032: eww: access bookmarks right from the URI prompt
Date: Sun, 08 Mar 2015 10:25:49 +0000	[thread overview]
Message-ID: <878uf7zsya.fsf@violet.siamics.net> (raw)
In-Reply-To: <87fv9gzj4e.fsf@violet.siamics.net> (Ivan Shmakov's message of "Sat, 07 Mar 2015 19:45:53 +0000")

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

>>>>> Ivan Shmakov <ivan@siamics.net> writes:

[…]

	That variant didn’t work quite well in practice.  The primary
	issue was that using 'display meant it wasn’t possible to search
	/annotations/ (using C-s, C-r, etc.) – only the URIs proper,
	which isn’t as nice as it could be.

	One another is that once we replace the use of 'display with
	appending the actual annotation to the value, with a non-nil
	'field property (for navigation purposes), move-end-of-line
	starts to misbehave in certain cases, apparently due to the fact
	that ‘line-move’ returns t after moving point to another /field/
	(as opposed to /line/.)  I haven’t identified the cause as of
	yet, but placing the title /before/ URI seems to make this
	problem harder to actually stumble upon.  Now given that there
	may be different preferences anyway, I’ve decided to introduce a
	new customizable variable for this one.

	(I’ve cleaned the new code up somewhat as well.)

	Please consider the revised patch MIMEd.

	* lisp/net/eww.el (eww-suggest-uris): Add eww-suggest-bookmarks
	to the default value and :options.  (Bug#20032)
	(eww-suggested-bookmarks-annotation): New customizable variable.
	(eww-suggest-bookmarks, eww-remove-annotation)
	(eww-substring-nil-property): New functions.
	(eww-suggested-uris, eww): Use eww-remove-annotation.

 > Somehow, I believe that eww-remove-annotation may be generalized
 > into something worthy of subr.el.

	(Or subr-x.el; or some other library.)  Generalized in the
	current revision of the patch as eww-substring-nil-property.

-- 
FSF associate member #7257  np. In the Garden — David Modica … B6A0 230E 334A

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/diff, Size: 4622 bytes --]

--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -64,7 +64,8 @@
 (defcustom eww-suggest-uris
   '(eww-links-at-point
     url-get-url-at-point
-    eww-current-url)
+    eww-current-url
+    eww-suggest-bookmarks)
   "List of functions called to form the list of default URIs for `eww'.
 Each of the elements is a function returning either a string or a list
 of strings.  The results will be joined into a single list with
@@ -74,7 +75,21 @@ defcustom eww-suggest-uris
   :type 'hook
   :options '(eww-links-at-point
 	     url-get-url-at-point
-	     eww-current-url))
+	     eww-current-url
+	     eww-suggest-bookmarks))
+
+(defcustom eww-suggested-bookmarks-annotation 'before
+  "Where to place annotation in the list of bookmarks at the URI prompt.
+This variable controls where the bookmark annotation (title) is placed.
+
+If 'before, annotation goes before URI.
+If 'after, annotation goes after URI.
+If nil, no annotation is provided."
+  :version "25.1"
+  :group 'eww
+  :type '(choice (const :tag "Annotation before URI" before)
+		 (const :tag "Annotation after URI" after)
+		 (const :tag "No annotation" nil)))
 
 (defcustom eww-bookmarks-directory user-emacs-directory
   "Directory where bookmark files will be stored."
@@ -234,9 +256,10 @@ defun eww-suggested-uris nil
     (dolist (fun eww-suggest-uris)
       (let ((ret (funcall fun)))
 	(dolist (uri (if (stringp ret) (list ret) ret))
-	  (when (and uri (not (intern-soft uri obseen)))
-	    (intern uri obseen)
-	    (push   uri uris)))))
+	  (let ((key (and uri (eww-remove-annotation uri))))
+	    (when (and key (not (intern-soft key obseen)))
+	      (intern key obseen)
+	      (push   uri uris))))))
     (nreverse uris)))
 
 ;;;###autoload
@@ -249,7 +272,9 @@ defun eww (url)
 	  (prompt (concat "Enter URL or keywords"
 			  (if uris (format " (default %s)" (car uris)) "")
 			  ": ")))
-     (list (read-string prompt nil nil uris))))
+     (let ((minibuffer-allow-text-properties t))
+       (list (eww-remove-annotation
+	      (read-string prompt nil nil uris))))))
   (setq url (string-trim url))
   (cond ((string-match-p "\\`file:/" url))
 	;; Don't mangle file: URLs at all.
@@ -549,6 +560,67 @@
 	(list (get-text-property (point) 'shr-url)
 	      (get-text-property (point) 'image-url))))
 
+(defun eww-suggested-bookmarks ()
+  "Return list of bookmarked URIs, if any.
+The URIs returned may contain arbitrary annotations.  Apply
+`eww-remove-annotation' on elements of the list returned to obtain the
+URIs proper."
+  (let* ((afterp (eq 'after eww-suggested-bookmarks-annotation))
+	 (prop (and eww-suggested-bookmarks-annotation
+		    (nconc (if afterp nil
+			     (list 'front-sticky t
+				   'rear-nonsticky t))
+			   '(field eww-title
+			     annotation t
+			     ; read-only t
+			     face minibuffer-prompt))))
+	 (fmt  (and prop
+		    (apply #'propertize
+			   (if afterp " (%s)" "(%s) ")
+			   prop))))
+    (mapcar (lambda (elt)
+	      (let ((uri (plist-get elt :url))
+		    (title (plist-get elt :title)))
+		(when uri
+		  (cond ((not fmt) uri)
+			(afterp (concat uri (format fmt title)))
+			(t      (concat (format fmt title) uri))))))
+	  eww-bookmarks)))
+
+(defun eww-remove-annotation (string &optional start limit)
+  (eww-substring-nil-property 'annotation string start limit))
+
+(defun eww-substring-nil-property (property &optional object start limit)
+  "Return the contents of OBJECT where PROPERTY is not set or nil.
+Return nil if all the contents of OBJECT has PROPERTY set and non-nil.
+
+OBJECT is either a string, buffer, or nil (which means the
+current buffer).
+
+If START is nil, use 0 for a string, or point for a buffer OBJECT.
+If LIMIT is nil, use string length for a string or (point-max) for a
+buffer."
+  (save-current-buffer
+    (cond ((stringp object))
+          (object
+           (set-buffer object)
+           (setq object nil)))
+    ;; From now on, object is either a string or nil.
+    (unless start
+      (setq start (if object 0 (point))))
+    (unless (or object limit)
+      (setq limit (point-max)))
+    (let ((acc  nil) 
+          (from start))
+      (while from
+        (let ((to (next-single-property-change from property object)))
+          (unless (get-text-property from property object)
+            (setq acc (concat acc
+                              (if object
+                                  (substring object from to)
+                                (buffer-substring from (or to limit))))))
+          (setq from to)))
+      acc)))
 (defun eww-view-source ()
   "View the HTML source code of the current page."
   (interactive)

  reply	other threads:[~2015-03-08 10:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-07 19:45 bug#20032: eww: access bookmarks right from the URI prompt Ivan Shmakov
2015-03-08 10:25 ` Ivan Shmakov [this message]
2015-12-25  6:35   ` Lars Ingebrigtsen
2015-12-26  8:57     ` Ivan Shmakov
2015-12-26 13:05       ` Lars Ingebrigtsen
2015-12-26 16:48         ` Ivan Shmakov
2015-12-26 17:00           ` Lars Ingebrigtsen
2016-02-02  4:33             ` Lars Ingebrigtsen
2017-01-24 22:44               ` Lars Ingebrigtsen
2015-12-25  6:25 ` Lars Ingebrigtsen
2015-12-26  9:42   ` Ivan Shmakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878uf7zsya.fsf@violet.siamics.net \
    --to=ivan@siamics.net \
    --cc=20032@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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