[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: [PATCH] w3m-lnum add highlight

The following message is a courtesy copy of an article
that has been posted to gmane.emacs.w3m as well.

Katsumi Yamaoka <yamaoka@xxxxxxx> writes:

> Thank you for the new patch.  Ok, we can do any kind of experiment
> since emacs-w3m is in the development state always (really? ;-).
> Now I can believe the rebinding of keys is useful to experienced
> users.  That's an ambitious approach; it may also be applicable
> to other Emacs programs.

I was thinking of this too.  Things could get abstracted away and maybe
lnum would live a life on its own as a library with w3m-lnum being its
poster specialisation.  Right now I can't think of known to me package
which would benefit as much as emacs-w3m but I guess I hardly know
0,00(0)1% of all elisp packages circulating around.  Whatever, next time
I feel like hitting `f' in an unrelated mode, I'll give it a good
thought.  And whoever likes this refreshed w3m-lnum might think even

> Installed in the CVS trunk.
> Regards,

Thanks.  I have a new set of little fixes.  I'd like to remove
`w3m-linknum-read-url' as it's now equivalent to
(car (w3m-linknum-get-action prompt 1))
which is not that more cumbersome and encourages to look at what other
information `w3m-linknum-get-action' gives for selection.  Feel free to
disregard this part of the diff.  But while still not widely used, why
not clean some duplication ;-) Here's ChangeLog.

2010-07-13  Andrey Kotlarski  <m00naticus@xxxxxxxxx>

	* w3m-lnum.el (w3m-link-numbering-mode): Using `buffer-list'
	instead of `w3m-list-buffers' as the latter does unnecessary
	(w3m-linknum-read-url): Removed. It's now equivalent to (car
	(w3m-linknum-get-action prompt 1))
	(w3m-linknum-toggle-inline-image): If no url under selected image,
	move over it and toggle it.
	(w3m-linknum-external-view-this-url, w3m-linknum-edit-this-url):
	Using `w3m-linknum-get-action' instead of
        * w3m.el (autoload): Added `w3m-link-numbering-mode', removed

Here's the diff against current cvs w3m-lnum.el and after that, a little
diff with w3m.el adding `w3m-link-numbering-mode' for autoload and
removing `w3m-linknum-read-url' (as noted, you might prefer it to stay).

--- w3m-lnum-cvs.el	2010-07-13 13:15:41.881203377 +0300
+++ w3m-lnum.el	        2010-07-13 14:32:33.693316589 +0300
@@ -164,9 +164,10 @@
 	(w3m-message "Link numbering keys off"))
       ;; change numbering status of all w3m buffers
-	(dolist (w3m-b (w3m-list-buffers t))
-	  (set-buffer w3m-b)
-	  (setq w3m-link-numbering-mode arg))))))
+	(dolist (buf (buffer-list))
+	  (set-buffer buf)
+	  (if (eq major-mode 'w3m-mode)
+	      (setq w3m-link-numbering-mode arg)))))))
 (defun w3m-link-numbering (&rest args)
   "Make overlays that display link numbers.
@@ -377,14 +378,6 @@
 			 (eval action)))))))
       (w3m-message "No valid link selected"))))
-(defun w3m-linknum-read-url (&optional prompt)
-  "Turn on link numbers and return PROMPT selected url.
-Highlight each intermediate result anchor."
-  (let ((link (w3m-linknum-get-action (or prompt "Link number: ") 1)))
-    (and link (stringp (setq link (car link)))
-	 link)))
 ;;; linknum alternatives to w3m user commands on point
@@ -392,7 +385,8 @@
 (defun w3m-linknum-toggle-inline-image (&optional arg)
   "If image at point, toggle it.
 Otherwise turn on link numbers and toggle selected image.
-With prefix ARG open in new session url behind image if such."
+With prefix ARG open url under image in new session.
+If no such url, move over image and toggle it."
   (interactive "P")
   (if (w3m-image)
       (let ((url (get-char-property (point) 'w3m-href-anchor)))
@@ -405,8 +399,12 @@
 		 "Toggle image: ")
       (if im
-	  (if (and arg (car im))
-	      (w3m-goto-url-new-session (car im))
+	  (if arg
+	      (if (car im)
+		  (w3m-goto-url-new-session (car im))
+		(push-mark (point))
+		(goto-char (cadr im))
+		(w3m-toggle-inline-image))
 	    (save-excursion (goto-char (cadr im))
 	(w3m-message "No image selected")))))
@@ -447,8 +445,9 @@
 If no link at point, turn on link numbers and open selected externally."
   (let ((url (w3m-url-valid (or (w3m-anchor) (w3m-image)
-				(w3m-linknum-read-url
-				 "Open in external browser: ")))))
+				(car
+				 (w3m-linknum-get-action
+				  "Open in external browser: " 1))))))
     (if url
 	(w3m-external-view url)
       (w3m-message "No URL selected"))))
@@ -458,13 +457,12 @@
   "Edit the page linked from the anchor under the cursor.
 If no such, turn on link numbers and edit selected."
-  (let ((url (w3m-url-valid (w3m-anchor))))
+  (let ((url (or (w3m-url-valid (w3m-anchor))
+		 (car (w3m-linknum-get-action
+		       "Select link to edit: " 1)))))
     (if url
 	(w3m-edit-url url)
-      (let ((link (w3m-linknum-read-url "Select link to edit: ")))
-	(if link
-	    (w3m-edit-url link)
-	  (w3m-message "No URL selected"))))))
+      (w3m-message "No URL selected"))))
 (defun w3m-linknum-print-this-url ()

--- w3m-cvs.el	2010-07-10 16:25:24.158519338 +0300
+++ w3m.el	2010-07-13 14:38:13.913207010 +0300
@@ -153,9 +153,9 @@
   (autoload 'report-emacs-w3m-bug "w3m-bug" nil t)
   (autoload 'w3m-replace-symbol "w3m-symbol" nil t)
   (autoload 'w3m-mail "w3m-mail" nil t)
+  (autoload 'w3m-link-numbering-mode "w3m-lnum" nil t)
   (autoload 'w3m-linknum-follow "w3m-lnum" nil t)
   (autoload 'w3m-go-to-linknum "w3m-lnum" nil t)
-  (autoload 'w3m-linknum-read-url "w3m-lnum")
   (autoload 'w3m-linknum-toggle-inline-image "w3m-lnum" nil t)
   (autoload 'w3m-linknum-view-image "w3m-lnum" nil t)
   (autoload 'w3m-linknum-external-view-this-url "w3m-lnum" nil t)