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

Re: [PATCH] w3m-lnum add highlight



Hello, 

thank you for making it work under other Emacsen as well.  Your changes
made me realise there are some other places that need this overlay start
workaround.  I also sneaked in a few optimisations and... Naming seems a
bit inconsistent and propose to radically put it in order by replacing
`w3m-linknum' and `w3m-link-numbering' prefixes with `w3m-lnum'.
Removed `w3m-go-to-linknum' (now `w3m-lnum-goto') from `C-c C-l' as it
is under `L F' anyway.  Obviously these changes will break existing use
(in code) of these functions but if there are any other users of this
sub-mode, I expect them not to have any problem ;) Also a few not that
specific functions and macros may go to w3m-util.el.  Here's the
proposed diff:


*** ChangeLog.~1.3373.~	2011-09-05 02:57:26.000000000 +0300
--- ChangeLog	2011-09-07 23:44:14.819705450 +0300
***************
*** 1,3 ****
--- 1,23 ----
+ 2011-09-07  Andrey Kotlarski  <m00naticus@xxxxxxxxx>
+ 
+ 	* w3m.el: Use `w3m-lnum' as naming prefix for commands and
+ 	maps from `w3m-lnum.el'.
+ 
+ 	* w3m-lnum.el: Use `w3m-lnum' as naming prefix everywhere instead of
+ 	`w3m-linknum' or `w3m-link-numbering'.
+ 	(w3m-lnum-set-numbering, w3m-lnum): Optionally don't clean previous
+ 	numbering.
+ 	(w3m-lnum-read-interactive): Don't clean previous numbering with
+ 	`w3m-lnum' in cases when there is no such.
+ 	(w3m-lnum-remove-overlays, w3m-lnum-set-numbering): Fix overlay start
+ 	range to make it work for XEmacs.
+ 	(w3m-lnum-get-action): Don't invoke `w3m-lnum-read-interactive' with 0
+ 	numbered items.
+ 
+ 	* w3m-util.el (w3m-goto-next-defun): New macro.
+ 	(w3m-goto-next-anchor-or-image, w3m-substitute-key-definitions): Move
+ 	from w3m-lnum.el
+ 
  2011-09-04  Katsumi Yamaoka  <yamaoka@xxxxxxx>
  
  	* w3m-lnum.el (w3m-link-numbering, w3m-linknum-minibuffer-prompt)
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1531
diff -c -r1.1531 w3m.el
*** w3m.el	3 Sep 2011 03:36:04 -0000	1.1531
--- w3m.el	7 Sep 2011 20:46:32 -0000
***************
*** 156,173 ****
    (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-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)
!   (autoload 'w3m-linknum-edit-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-linknum-print-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-linknum-download-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-linknum-bookmark-add-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-linknum-zoom-in-image "w3m-lnum" nil t)
!   (autoload 'w3m-linknum-zoom-out-image "w3m-lnum" nil t)
    (autoload 'w3m-session-select "w3m-session"
      "Select session from session list." t)
    (autoload 'w3m-session-save "w3m-session"
--- 156,173 ----
    (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-lnum-mode "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-follow "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-goto "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-toggle-inline-image "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-view-image "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-external-view-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-edit-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-print-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-download-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-bookmark-add-this-url "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-zoom-in-image "w3m-lnum" nil t)
!   (autoload 'w3m-lnum-zoom-out-image "w3m-lnum" nil t)
    (autoload 'w3m-session-select "w3m-session"
      "Select session from session list." t)
    (autoload 'w3m-session-save "w3m-session"
***************
*** 7823,7829 ****
      (define-key map "\C-c" 'w3m-submit-form)
      (define-key map "\C-k" 'w3m-process-stop)
      (define-key map "\C-m" 'w3m-move-unseen-buffer)
-     (define-key map "\C-l" 'w3m-go-to-linknum)
      (setq w3m-ctl-c-map map)))
  
  (defvar w3m-redisplay-map nil
--- 7823,7828 ----
***************
*** 7835,7856 ****
      (define-key map "C" 'w3m-redisplay-and-reset)
      (setq w3m-redisplay-map map)))
  
! (defvar w3m-linknum-map nil
    "Sub-keymap used for the `L'-prefixed link numbering commands.")
! (unless w3m-linknum-map
    (let ((map (make-sparse-keymap)))
!     (define-key map "F" 'w3m-go-to-linknum)
!     (define-key map "I" 'w3m-linknum-view-image)
!     (define-key map "\M-i" 'w3m-linknum-save-image)
!     (define-key map "d" 'w3m-linknum-download-this-url)
!     (define-key map "e" 'w3m-linknum-edit-this-url)
!     (define-key map "f" 'w3m-linknum-follow)
!     (define-key map "t" 'w3m-linknum-toggle-inline-image)
!     (define-key map "u" 'w3m-linknum-print-this-url)
!     (define-key map "b" 'w3m-linknum-bookmark-add-this-url)
!     (define-key map "]" 'w3m-linknum-zoom-in-image)
!     (define-key map "[" 'w3m-linknum-zoom-out-image)
!     (setq w3m-linknum-map map)))
  
  (defvar w3m-lynx-like-map nil
    "Lynx-like keymap used in emacs-w3m buffers.")
--- 7834,7855 ----
      (define-key map "C" 'w3m-redisplay-and-reset)
      (setq w3m-redisplay-map map)))
  
! (defvar w3m-lnum-map nil
    "Sub-keymap used for the `L'-prefixed link numbering commands.")
! (unless w3m-lnum-map
    (let ((map (make-sparse-keymap)))
!     (define-key map "F" 'w3m-lnum-goto)
!     (define-key map "I" 'w3m-lnum-view-image)
!     (define-key map "\M-i" 'w3m-lnum-save-image)
!     (define-key map "d" 'w3m-lnum-download-this-url)
!     (define-key map "e" 'w3m-lnum-edit-this-url)
!     (define-key map "f" 'w3m-lnum-follow)
!     (define-key map "t" 'w3m-lnum-toggle-inline-image)
!     (define-key map "u" 'w3m-lnum-print-this-url)
!     (define-key map "b" 'w3m-lnum-bookmark-add-this-url)
!     (define-key map "]" 'w3m-lnum-zoom-in-image)
!     (define-key map "[" 'w3m-lnum-zoom-out-image)
!     (setq w3m-lnum-map map)))
  
  (defvar w3m-lynx-like-map nil
    "Lynx-like keymap used in emacs-w3m buffers.")
***************
*** 7964,7970 ****
      (define-key map "|" 'w3m-pipe-source)
      (define-key map "\C-c" w3m-ctl-c-map)
      (define-key map "C" w3m-redisplay-map)
!     (define-key map "L" w3m-linknum-map)
      (setq w3m-lynx-like-map map)))
  
  (defvar w3m-info-like-map nil
--- 7963,7969 ----
      (define-key map "|" 'w3m-pipe-source)
      (define-key map "\C-c" w3m-ctl-c-map)
      (define-key map "C" w3m-redisplay-map)
!     (define-key map "L" w3m-lnum-map)
      (setq w3m-lynx-like-map map)))
  
  (defvar w3m-info-like-map nil
***************
*** 8082,8088 ****
      (define-key map "|" 'w3m-pipe-source)
      (define-key map "\C-c" w3m-ctl-c-map)
      (define-key map "C" w3m-redisplay-map)
!     (define-key map "L" w3m-linknum-map)
      (setq w3m-info-like-map map)))
  
  (defun w3m-alive-p (&optional visible)
--- 8081,8087 ----
      (define-key map "|" 'w3m-pipe-source)
      (define-key map "\C-c" w3m-ctl-c-map)
      (define-key map "C" w3m-redisplay-map)
!     (define-key map "L" w3m-lnum-map)
      (setq w3m-info-like-map map)))
  
  (defun w3m-alive-p (&optional visible)
***************
*** 8422,8428 ****
  
  \\[w3m-next-anchor]	Move the point to the next anchor.
  \\[w3m-previous-anchor]	Move the point to the previous anchor.
- \\[w3m-go-to-linknum] Move the point to the numbered anchor.
  \\[w3m-next-form]	Move the point to the next form.
  \\[w3m-previous-form]	Move the point to the previous form.
  \\[w3m-next-image]	Move the point to the next image.
--- 8421,8426 ----
Index: w3m-util.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-util.el,v
retrieving revision 1.147
diff -c -r1.147 w3m-util.el
*** w3m-util.el	7 Jul 2011 10:00:03 -0000	1.147
--- w3m-util.el	7 Sep 2011 20:46:32 -0000
***************
*** 745,755 ****
--- 745,813 ----
  		(delete-window window)))))))))
  
  
+ ;;; Navigation:
+ 
+ (defmacro w3m-goto-next-defun (name property)
+   "Create function w3m-goto-next- NAME.
+ Return position of the first occurence of PROPERTY.
+ If currently over such PROPERTY, find next such occurence."
+   `(defun ,(intern (concat "w3m-goto-next-" (symbol-name name)))
+      (&optional pos)
+      ,(concat "Return position of next " (symbol-name name)
+ 	      " starting from POS or point.")
+      (setq pos (or pos (point)))
+      (if (get-char-property pos ',property) ; currently over such element
+ 	 (setq pos (next-single-property-change pos ',property)))
+      (if (or (get-char-property pos ',property)
+ 	     (setq pos (next-single-property-change pos ',property)))
+ 	 pos)))
+ 
+ (w3m-goto-next-defun link w3m-href-anchor)
+ (w3m-goto-next-defun image2 w3m-image)
+ 
+ (defun w3m-goto-next-anchor-or-image (&optional pos)
+   "Return position of next anchor or image starting from POS or point."
+   (setq pos (or pos (point)))
+   (cond				; currently on anchor or image
+    ((w3m-anchor-sequence pos)
+     (setq pos (next-single-property-change pos 'w3m-anchor-sequence)))
+    ((w3m-image pos)
+     (setq pos (next-single-property-change pos 'w3m-image))))
+   (or (w3m-anchor-sequence pos)
+       (w3m-image pos)
+       (let ((image-pos (next-single-property-change pos 'w3m-image)))
+ 	(setq pos (next-single-property-change pos
+ 					       'w3m-anchor-sequence))
+ 	(and image-pos
+ 	     (or (not pos) (> pos image-pos))
+ 	     (setq pos image-pos))))
+   (if pos
+       (let ((hseq (w3m-anchor-sequence pos)))
+ 	(if (and hseq (text-property-any ; multiline anchors
+ 		       (point-min) pos 'w3m-anchor-sequence hseq))
+ 	    (w3m-goto-next-anchor-or-image pos)
+ 	  pos))))
+ 
+ 
  ;;; Miscellaneous:
  
  (defconst w3m-url-fallback-base "http:///")
  (defconst w3m-url-invalid-regexp "\\`http:///")
  
+ (defmacro w3m-substitute-key-definitions (new-map old-map &rest keys)
+   "In NEW-MAP substitute cascade of OLD-MAP KEYS.
+ KEYS is alternating list of key-value."
+   (let ((n-map new-map)
+ 	(o-map old-map))
+     `(progn
+        ,@(let ((res nil))
+ 	   (while keys
+ 	     (push `(substitute-key-definition
+ 		     ,(car keys) ,(cadr keys) ,n-map ,o-map)
+ 		   res)
+ 	     (setq keys (cddr keys)))
+ 	   (nreverse res)))))
+ 
  (defun w3m-url-valid (url)
    (and url (not (string-match w3m-url-invalid-regexp url))
         url))
Index: w3m-lnum.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-lnum.el,v
retrieving revision 1.33
diff -c -r1.33 w3m-lnum.el
*** w3m-lnum.el	4 Sep 2011 23:52:19 -0000	1.33
--- w3m-lnum.el	7 Sep 2011 20:46:33 -0000
***************
*** 28,35 ****
  ;; This file provides a minor mode to enable Conkeror style operations
  ;; using link numbers.  Mostly point operations are extended beyond
  ;; current point but there are also new features like
! ;; `w3m-go-to-linknum' for quickly navigating to links, form fields
! ;; images or buttons and `w3m-linknum-follow' for visiting links,
  ;; activating form fields, toggling images or pushing buttons.
  
  ;;; Usage:
--- 28,35 ----
  ;; This file provides a minor mode to enable Conkeror style operations
  ;; using link numbers.  Mostly point operations are extended beyond
  ;; current point but there are also new features like
! ;; `w3m-lnum-goto' for quickly navigating to links, form fields
! ;; images or buttons and `w3m-lnum-follow' for visiting links,
  ;; activating form fields, toggling images or pushing buttons.
  
  ;;; Usage:
***************
*** 37,53 ****
  ;; Install this file to an appropriate directory, and add this
  ;; expression to your ~/.emacs-w3m if you want automatically
  ;; activating this minor mode
! ;; (w3m-link-numbering-mode 1)
  ;; or alternatively this to your .emacs file before loading w3m
! ;; (add-hook 'w3m-mode-hook 'w3m-link-numbering-mode)
! ;; or just use interactive command `w3m-link-numbering-mode' to toggle
  ;; mode.
  
  ;;; Code:
  
  (require 'w3m)
  
! (defface w3m-link-numbering
    '((((class color) (min-colors 16) (background light))
       (:foreground "gray60"))
      (((class color) (min-colors 16) (background dark))
--- 37,53 ----
  ;; Install this file to an appropriate directory, and add this
  ;; expression to your ~/.emacs-w3m if you want automatically
  ;; activating this minor mode
! ;; (w3m-lnum-mode 1)
  ;; or alternatively this to your .emacs file before loading w3m
! ;; (add-hook 'w3m-mode-hook 'w3m-lnum-mode)
! ;; or just use interactive command `w3m-lnum-mode' to toggle
  ;; mode.
  
  ;;; Code:
  
  (require 'w3m)
  
! (defface w3m-lnum
    '((((class color) (min-colors 16) (background light))
       (:foreground "gray60"))
      (((class color) (min-colors 16) (background dark))
***************
*** 56,71 ****
    "Face used to highlight link numbers."
    :group 'w3m-face)
  ;; backward-compatibility alias
! (put 'w3m-link-numbering-face 'face-alias 'w3m-link-numbering)
  
! (defface w3m-linknum-minibuffer-prompt
!   '((((class color) (background light) (type tty)) (:foreground "blue"))
      (((class color) (background dark)) (:foreground "cyan"))
      (t (:foreground "medium blue")))
!   "Face for w3m linknum minibuffer prompt."
    :group 'w3m-face)
  
! (defface w3m-linknum-match
    '((((class color) (background light) (type tty))
       (:background "yellow" :foreground "black"))
      (((class color) (background dark) (type tty))
--- 56,72 ----
    "Face used to highlight link numbers."
    :group 'w3m-face)
  ;; backward-compatibility alias
! (put 'w3m-lnum-face 'face-alias 'w3m-lnum)
  
! (defface w3m-lnum-minibuffer-prompt
!   '((((class color) (background light) (type tty))
!      (:foreground "blue"))
      (((class color) (background dark)) (:foreground "cyan"))
      (t (:foreground "medium blue")))
!   "Face for w3m lnum minibuffer prompt."
    :group 'w3m-face)
  
! (defface w3m-lnum-match
    '((((class color) (background light) (type tty))
       (:background "yellow" :foreground "black"))
      (((class color) (background dark) (type tty))
***************
*** 73,212 ****
      (((class color) (background light)) (:background "yellow1"))
      (((class color) (background dark)) (:background "RoyalBlue3"))
      (t (:background "gray")))
!   "Face used to highlight matches in `w3m-link-numbering-mode'."
    :group 'w3m-face)
  
! (defcustom w3m-link-numbering-mode-hook nil
!   "*Hook run after command `w3m-link-numbering-mode' initialization."
    :group 'w3m
    :type 'hook)
  
! (defcustom w3m-link-numbering-quick-browsing nil
    "If non-nil, do aggressive selection.  Possible values are:
  `quick-numbers' quick selection only when entering numbers.
  `quick-filter' ditto only when filtering.
  `quick-all' always quick selecting."
!   :group 'w3m
!   :type 'boolean)
  
! (defcustom w3m-link-numbering-context-alist
!   '(("news.ycombinator.com" 2) ("reddit.com" 1))
    "Alist specifying number of additional items to be numbered after
  filtering over an url being matched by the car."
!   :group 'w3m)
  
! (defmacro w3m-substitute-key-definitions (new-map old-map &rest keys)
!   "In NEW-MAP substitute cascade of OLD-MAP KEYS.
! KEYS is alternating list of key-value."
!   (let ((n-map new-map)
! 	(o-map old-map))
!     `(progn
!        ,@(let ((res nil))
! 	   (while keys
! 	     (push `(substitute-key-definition
! 		     ,(car keys) ,(cadr keys) ,n-map ,o-map)
! 		   res)
! 	     (setq keys (cddr keys)))
! 	   (nreverse res)))))
! 
! (defvar w3m-link-numbering-mode-map nil
!   "Keymap used when command `w3m-link-numbering-mode' is active.")
! (unless w3m-link-numbering-mode-map
    (let ((map (make-sparse-keymap)))
!     (define-key map "f" 'w3m-linknum-follow)
!     (define-key map "F" 'w3m-go-to-linknum)
      (w3m-substitute-key-definitions
       map w3m-mode-map
!      'w3m-view-image 'w3m-linknum-view-image
!      'w3m-save-image 'w3m-linknum-save-image
!      'w3m-download-this-url 'w3m-linknum-download-this-url
!      'w3m-edit-this-url 'w3m-linknum-edit-this-url
!      'w3m-toggle-inline-image 'w3m-linknum-toggle-inline-image
!      'w3m-print-this-url 'w3m-linknum-print-this-url
!      'w3m-external-view-this-url 'w3m-linknum-external-view-this-url
!      'w3m-bookmark-add-this-url 'w3m-linknum-bookmark-add-this-url
!      'w3m-zoom-in-image 'w3m-linknum-zoom-in-image
!      'w3m-zoom-out-image 'w3m-linknum-zoom-out-image)
!     (setq w3m-link-numbering-mode-map map)))
  
! (defvar w3m-link-numbering-mode nil
    "Non-nil if w3m operations using link numbers are enabled.")
! (make-variable-buffer-local 'w3m-link-numbering-mode)
! (unless (assq 'w3m-link-numbering-mode minor-mode-alist)
!   (push (list 'w3m-link-numbering-mode "[ln]") minor-mode-alist))
! (unless (assq 'w3m-link-numbering-mode minor-mode-map-alist)
!   (push (cons 'w3m-link-numbering-mode w3m-link-numbering-mode-map)
  	minor-mode-map-alist))
  
! (defun w3m-linknum-remove-overlays ()
    "Remove numbering and match overlays."
!   (dolist (overlay (overlays-in (window-start) (window-end)))
!     (if (or (overlay-get overlay 'w3m-link-numbering-overlay)
! 	    (overlay-get overlay 'w3m-linknum-match))
  	(delete-overlay overlay))))
  
  ;;;###autoload
! (defun w3m-link-numbering-mode (&optional arg)
    "Minor mode to extend point commands by using Conkeror style number selection.
  With prefix ARG 0 disable battery included point functions, otherwise
  enable them.  With no prefix ARG - toggle."
    (interactive "P")
!   (let ((w3m-linknum-status w3m-link-numbering-mode))
      ;; find current numbering status of w3m buffers
      (or (eq major-mode 'w3m-mode)
  	(save-current-buffer
! 	  (setq w3m-linknum-status
  		(catch 'found-w3m
  		  (dolist (buf (buffer-list))
  		    (set-buffer buf)
  		    (if (eq major-mode 'w3m-mode)
  			(throw 'found-w3m
! 			       w3m-link-numbering-mode)))))))
      (setq arg (not (if arg (zerop arg)
! 		     w3m-linknum-status)))
!     (unless (eq arg w3m-linknum-status)	; if change of mode status
        (if arg
! 	  (progn (add-hook 'w3m-mode-hook 'w3m-link-numbering-mode)
! 		 (run-hooks 'w3m-link-numbering-mode-hook)
  		 (w3m-message "Link numbering keys on"))
! 	(remove-hook 'w3m-mode-hook 'w3m-link-numbering-mode)
  	(w3m-message "Link numbering keys off"))
        ;; change numbering status of all w3m buffers
        (save-current-buffer
  	(dolist (buf (buffer-list))
  	  (set-buffer buf)
  	  (if (eq major-mode 'w3m-mode)
! 	      (setq w3m-link-numbering-mode arg)))))))
  
! (defmacro w3m-link-set-overlay (pos index)
!   "Set numbering overlay at POS with INDEX."
    `(let ((overlay (make-overlay ,pos (1+ ,pos))))
       (let ((num (format "[%d]" (setq ,index (1+ ,index)))))
         (overlay-put overlay 'before-string num)
         (w3m-static-if (featurep 'xemacs)
! 	   (set-glyph-face (extent-begin-glyph overlay)
! 			   'w3m-link-numbering)
! 	 (w3m-add-face-property 0 (length num)
! 				'w3m-link-numbering num)
  	 (overlay-put overlay 'evaporate t)))
!      (overlay-put overlay 'w3m-link-numbering-overlay ,index)
       (let ((hseq (get-char-property ,pos 'w3m-anchor-sequence))
  	   (pos2 ,pos))
         (if hseq				; multiline anchors
! 	   (let ((pmax (window-end)))
! 	     (while (and (setq pos2 (next-single-property-change
! 				     pos2 'w3m-anchor-sequence))
! 			 (setq pos2 (text-property-any
! 				     pos2 pmax
! 				     'w3m-anchor-sequence hseq)))
! 	       (setq overlay (make-overlay pos2 (1+ pos2)))
! 	       (overlay-put overlay 'w3m-link-numbering-overlay
! 			    ,index)))))))
  
! (defun w3m-link-set-numbering (&optional next-func reg)
    "Make overlays that display link numbers.  Return last used index.
  NEXT-FUNC is function to iterate numbered elements, if not given,
! use `w3m-goto-next-anchor-or-image'.  REG is filter string for anchor text."
    (setq reg
  	(if reg
  	    (w3m-replace-regexps-in-string ; escape special characters
--- 74,197 ----
      (((class color) (background light)) (:background "yellow1"))
      (((class color) (background dark)) (:background "RoyalBlue3"))
      (t (:background "gray")))
!   "Face used to highlight matches in `w3m-lnum-mode'."
    :group 'w3m-face)
  
! (defcustom w3m-lnum-mode-hook nil
!   "*Hook run after command `w3m-lnum-mode' initialization."
    :group 'w3m
    :type 'hook)
  
! (defcustom w3m-lnum-quick-browsing nil
    "If non-nil, do aggressive selection.  Possible values are:
  `quick-numbers' quick selection only when entering numbers.
  `quick-filter' ditto only when filtering.
  `quick-all' always quick selecting."
!   :group 'w3m)
  
! (defcustom w3m-lnum-context-alist
!   '(("news.ycombinator.com" . 2) ("reddit.com" . 1))
    "Alist specifying number of additional items to be numbered after
  filtering over an url being matched by the car."
!   :group 'w3m
!   :type 'alist)
  
! (defvar w3m-lnum-mode-map nil
!   "Keymap used when command `w3m-lnum-mode' is active.")
! (unless w3m-lnum-mode-map
    (let ((map (make-sparse-keymap)))
!     (define-key map "f" 'w3m-lnum-follow)
!     (define-key map "F" 'w3m-lnum-goto)
      (w3m-substitute-key-definitions
       map w3m-mode-map
!      'w3m-view-image 'w3m-lnum-view-image
!      'w3m-save-image 'w3m-lnum-save-image
!      'w3m-download-this-url 'w3m-lnum-download-this-url
!      'w3m-edit-this-url 'w3m-lnum-edit-this-url
!      'w3m-toggle-inline-image 'w3m-lnum-toggle-inline-image
!      'w3m-print-this-url 'w3m-lnum-print-this-url
!      'w3m-external-view-this-url 'w3m-lnum-external-view-this-url
!      'w3m-bookmark-add-this-url 'w3m-lnum-bookmark-add-this-url
!      'w3m-zoom-in-image 'w3m-lnum-zoom-in-image
!      'w3m-zoom-out-image 'w3m-lnum-zoom-out-image)
!     (setq w3m-lnum-mode-map map)))
  
! (defvar w3m-lnum-mode nil
    "Non-nil if w3m operations using link numbers are enabled.")
! (make-variable-buffer-local 'w3m-lnum-mode)
! (unless (assq 'w3m-lnum-mode minor-mode-alist)
!   (push (list 'w3m-lnum-mode "[ln]") minor-mode-alist))
! (unless (assq 'w3m-lnum-mode minor-mode-map-alist)
!   (push (cons 'w3m-lnum-mode w3m-lnum-mode-map)
  	minor-mode-map-alist))
  
! (defun w3m-lnum-remove-overlays ()
    "Remove numbering and match overlays."
!   (dolist (overlay (overlays-in (max (1- (window-start)) (point-min))
! 				(window-end)))
!     (if (or (overlay-get overlay 'w3m-lnum-overlay)
! 	    (overlay-get overlay 'w3m-lnum-match))
  	(delete-overlay overlay))))
  
  ;;;###autoload
! (defun w3m-lnum-mode (&optional arg)
    "Minor mode to extend point commands by using Conkeror style number selection.
  With prefix ARG 0 disable battery included point functions, otherwise
  enable them.  With no prefix ARG - toggle."
    (interactive "P")
!   (let ((w3m-lnum-status w3m-lnum-mode))
      ;; find current numbering status of w3m buffers
      (or (eq major-mode 'w3m-mode)
  	(save-current-buffer
! 	  (setq w3m-lnum-status
  		(catch 'found-w3m
  		  (dolist (buf (buffer-list))
  		    (set-buffer buf)
  		    (if (eq major-mode 'w3m-mode)
  			(throw 'found-w3m
! 			       w3m-lnum-mode)))))))
      (setq arg (not (if arg (zerop arg)
! 		     w3m-lnum-status)))
!     (unless (eq arg w3m-lnum-status)	; if change of mode status
        (if arg
! 	  (progn (add-hook 'w3m-mode-hook 'w3m-lnum-mode)
! 		 (run-hooks 'w3m-lnum-mode-hook)
  		 (w3m-message "Link numbering keys on"))
! 	(remove-hook 'w3m-mode-hook 'w3m-lnum-mode)
  	(w3m-message "Link numbering keys off"))
        ;; change numbering status of all w3m buffers
        (save-current-buffer
  	(dolist (buf (buffer-list))
  	  (set-buffer buf)
  	  (if (eq major-mode 'w3m-mode)
! 	      (setq w3m-lnum-mode arg)))))))
  
! (defmacro w3m-lnum-set-overlay (pos index pmax)
!   "Set numbering overlay at POS with INDEX and until PMAX."
    `(let ((overlay (make-overlay ,pos (1+ ,pos))))
       (let ((num (format "[%d]" (setq ,index (1+ ,index)))))
         (overlay-put overlay 'before-string num)
         (w3m-static-if (featurep 'xemacs)
! 	   (set-glyph-face (extent-begin-glyph overlay) 'w3m-lnum)
! 	 (w3m-add-face-property 0 (length num) 'w3m-lnum num)
  	 (overlay-put overlay 'evaporate t)))
!      (overlay-put overlay 'w3m-lnum-overlay ,index)
       (let ((hseq (get-char-property ,pos 'w3m-anchor-sequence))
  	   (pos2 ,pos))
         (if hseq				; multiline anchors
! 	   (while (and (setq pos2 (next-single-property-change
! 				   pos2 'w3m-anchor-sequence))
! 		       (setq pos2 (text-property-any
! 				   pos2 ,pmax
! 				   'w3m-anchor-sequence hseq)))
! 	     (setq overlay (make-overlay pos2 (1+ pos2)))
! 	     (overlay-put overlay 'w3m-lnum-overlay ,index))))))
  
! (defun w3m-lnum-set-numbering (&optional next-func reg dont-clear-p)
    "Make overlays that display link numbers.  Return last used index.
  NEXT-FUNC is function to iterate numbered elements, if not given,
! use `w3m-goto-next-anchor-or-image'.  REG is filter string for anchor text.
! DONT-CLEAR-P determines whether previous numbering has to be cleared."
    (setq reg
  	(if reg
  	    (w3m-replace-regexps-in-string ; escape special characters
***************
*** 215,230 ****
  	     "\\$" "\\\\$")
  	  "")
  	next-func (or next-func 'w3m-goto-next-anchor-or-image))
!   (let ((pos (window-start))
  	(pmax (window-end)))
!     (dolist (overlay (overlays-in pos pmax))
!       (if (overlay-get overlay 'w3m-link-numbering-overlay)
! 	  (delete-overlay overlay)))
      (let ((index 0)
! 	  (context (or (car (assoc-default
! 			     w3m-current-url
! 			     w3m-link-numbering-context-alist
! 			     'w3m-string-match-p))
  		       0)))
        (while (and pos
  		  (setq pos (funcall next-func pos))
--- 200,215 ----
  	     "\\$" "\\\\$")
  	  "")
  	next-func (or next-func 'w3m-goto-next-anchor-or-image))
!   (let ((pos (max (1- (window-start)) (point-min)))
  	(pmax (window-end)))
!     (unless dont-clear-p
!       (dolist (overlay (overlays-in pos pmax))
! 	(if (overlay-get overlay 'w3m-lnum-overlay)
! 	    (delete-overlay overlay))))
      (let ((index 0)
! 	  (context (or (assoc-default w3m-current-url
! 				      w3m-lnum-context-alist
! 				      'w3m-string-match-p)
  		       0)))
        (while (and pos
  		  (setq pos (funcall next-func pos))
***************
*** 256,326 ****
  					     ((w3m-image pos)
  					      'w3m-image))))
  				     str))
! 	    (w3m-link-set-overlay pos index)
  	    (let ((counter context))
  	      (while (and (>= (setq counter (1- counter)) 0)
  			  (setq pos (funcall next-func pos))
  			  (< pos pmax))
! 		(w3m-link-set-overlay pos index))))))
        index)))
  
! (defun w3m-goto-next-link (&optional pos)
!   "Return position of next link starting from POS or point."
!   (setq pos (or pos (point)))
!   (if (get-char-property pos 'w3m-href-anchor) ; currently over link
!       (setq pos (next-single-property-change pos 'w3m-href-anchor)))
!   (if (or (get-char-property pos 'w3m-href-anchor)
! 	  (setq pos (next-single-property-change pos
! 						 'w3m-href-anchor)))
!       pos))
! 
! (defun w3m-goto-next-image2 (&optional pos)
!   "Return position of next image starting from POS or point."
!   (setq pos (or pos (point)))
!   (if (get-char-property pos 'w3m-image) ; currently over image
!       (setq pos (next-single-property-change pos 'w3m-image)))
!   (if (or (get-char-property pos 'w3m-image)
! 	  (setq pos (next-single-property-change pos 'w3m-image)))
!       pos))
! 
! (defun w3m-goto-next-anchor-or-image (&optional pos)
!   "Return position of next anchor or image starting from POS or point."
!   (setq pos (or pos (point)))
!   (cond				; currently on anchor or image
!    ((w3m-anchor-sequence pos)
!     (setq pos (next-single-property-change pos
! 					   'w3m-anchor-sequence)))
!    ((w3m-image pos)
!     (setq pos (next-single-property-change pos 'w3m-image))))
!   (or (w3m-anchor-sequence pos)
!       (w3m-image pos)
!       (let ((image-pos (next-single-property-change pos 'w3m-image)))
! 	(setq pos (next-single-property-change pos
! 					       'w3m-anchor-sequence))
! 	(and image-pos
! 	     (or (not pos) (> pos image-pos))
! 	     (setq pos image-pos))))
!   (if pos
!       (let ((hseq (w3m-anchor-sequence pos)))
! 	(if (and hseq (text-property-any ; multiline anchors
! 		       (point-min) pos 'w3m-anchor-sequence hseq))
! 	    (w3m-goto-next-anchor-or-image pos)
! 	  pos))))
! 
! (defun w3m-link-numbering (arg &optional str)
    "Make overlays that display link numbers.  Return last used index.
  With ARG 0 clear numbering overlay.  With ARG 1 index only links.
  With ARG 2 index only images.  Otherwise index all anchors.
! STR is filter string for anchor text."
!   (if (zerop arg) (w3m-linknum-remove-overlays)
!     (w3m-link-set-numbering (cond ((= arg 1) 'w3m-goto-next-link)
  				  ((= arg 2) 'w3m-goto-next-image2)
  				  (t 'w3m-goto-next-anchor-or-image))
! 			    str)))
  
! (defmacro w3m-linknum-prompt-str (num fun start def-anchor str
! 				      &optional show-num)
!   "Construct a prompt string for function `w3m-read-int-interactive'.
  NUM is a number variable for currently to be selected element.
  FUN is a function to be called with NUM as argument.
  START is a string to start the prompt.
--- 241,269 ----
  					     ((w3m-image pos)
  					      'w3m-image))))
  				     str))
! 	    (w3m-lnum-set-overlay pos index pmax)
  	    (let ((counter context))
  	      (while (and (>= (setq counter (1- counter)) 0)
  			  (setq pos (funcall next-func pos))
  			  (< pos pmax))
! 		(w3m-lnum-set-overlay pos index pmax))))))
        index)))
  
! (defun w3m-lnum (arg &optional str dont-clear-p)
    "Make overlays that display link numbers.  Return last used index.
  With ARG 0 clear numbering overlay.  With ARG 1 index only links.
  With ARG 2 index only images.  Otherwise index all anchors.
! STR is filter string for anchor text.
! DONT-CLEAR-P determines whether previous numbering has to be cleared."
!   (if (zerop arg) (w3m-lnum-remove-overlays)
!     (w3m-lnum-set-numbering (cond ((= arg 1) 'w3m-goto-next-link)
  				  ((= arg 2) 'w3m-goto-next-image2)
  				  (t 'w3m-goto-next-anchor-or-image))
! 			    str dont-clear-p)))
  
! (defmacro w3m-lnum-prompt-str (num fun start def-anchor str
! 				   &optional show-num)
!   "Construct a prompt string for function `w3m-lnum-read-interactive'.
  NUM is a number variable for currently to be selected element.
  FUN is a function to be called with NUM as argument.
  START is a string to start the prompt.
***************
*** 336,346 ****
       (concat ,start
  	     (or show-num (propertize
  			   (number-to-string ,num)
! 			   'face 'w3m-linknum-minibuffer-prompt))
  	     " " ,str anchor)))
  
! (defun w3m-read-int-interactive (prompt fun type last-index
! 					&optional def-anchor)
    "Interactively read a valid integer from minubuffer with PROMPT.
  Execute a one argument function FUN with every current valid integer.
  TYPE is type of link numbering.  DEF-ANCHOR is initial element to print.
--- 279,289 ----
       (concat ,start
  	     (or show-num (propertize
  			   (number-to-string ,num)
! 			   'face 'w3m-lnum-minibuffer-prompt))
  	     " " ,str anchor)))
  
! (defun w3m-lnum-read-interactive (prompt fun type last-index
! 					 &optional def-anchor)
    "Interactively read a valid integer from minubuffer with PROMPT.
  Execute a one argument function FUN with every current valid integer.
  TYPE is type of link numbering.  DEF-ANCHOR is initial element to print.
***************
*** 350,368 ****
  Entering 0 may choose default anchor without <return>.
  Every other character is appended to a filtering string.
  <CTRL>+<NUMBER> is appended to the filtering string as <NUMBER>.
! If `w3m-link-numbering-quick-browse' is non-nil, choose without
  <return> on single possible selection."
    (setq def-anchor (if def-anchor (concat " [" def-anchor "]")
  		     "")
  	prompt (propertize prompt 'face
! 			   'w3m-linknum-minibuffer-prompt))
    (let ((num 1)
  	(str "")
  	(auto-num t)
  	ch key)
      (catch 'select
!       (let ((temp-prompt (w3m-linknum-prompt-str num fun prompt
! 						 def-anchor "" "")))
  	(while (not (memq		; while not return or escape
  		     (setq ch
  			   (w3m-static-if (featurep 'xemacs)
--- 293,311 ----
  Entering 0 may choose default anchor without <return>.
  Every other character is appended to a filtering string.
  <CTRL>+<NUMBER> is appended to the filtering string as <NUMBER>.
! If `w3m-lnum-quick-browse' is non-nil, choose without
  <return> on single possible selection."
    (setq def-anchor (if def-anchor (concat " [" def-anchor "]")
  		     "")
  	prompt (propertize prompt 'face
! 			   'w3m-lnum-minibuffer-prompt))
    (let ((num 1)
  	(str "")
  	(auto-num t)
  	ch key)
      (catch 'select
!       (let ((temp-prompt (w3m-lnum-prompt-str num fun prompt
! 					      def-anchor "" "")))
  	(while (not (memq		; while not return or escape
  		     (setq ch
  			   (w3m-static-if (featurep 'xemacs)
***************
*** 382,416 ****
  		(unless (string-equal str "") ; delete last filter character
  		  (setq num 1
  			last-index
! 			(w3m-link-numbering
  			 type (setq str (w3m-substring-no-properties
  					 str 0 (1- (length str)))))
  			temp-prompt
! 			(w3m-linknum-prompt-str num fun prompt
! 						def-anchor str "")))
  	      (setq num (/ num 10))	; delete last digit
  	      (if (zerop num)
  		  (setq num 1
  			auto-num t))
  	      (setq temp-prompt
! 		    (w3m-linknum-prompt-str num fun prompt
! 					    def-anchor str
! 					    (if auto-num "")))))
  	   ;; scroll options
  	   ((memq ch '(32 ?\ ))		; scroll down
! 	    (w3m-linknum-remove-overlays)
  	    (ignore-errors
  	      (w3m-scroll-up-1)
  	      (redisplay))   ; scroll-up sets wrongly window-start/end
  	    #1=
! 	    (setq last-index (w3m-link-numbering type str)
  		  num (if (zerop last-index) 0 1)
  		  auto-num t
! 		  temp-prompt (w3m-linknum-prompt-str num fun prompt
! 						      def-anchor
! 						      str "")))
  	   ((eq ch 'delete)		; scroll up
! 	    (w3m-linknum-remove-overlays)
  	    (ignore-errors (scroll-down nil))
  	    #1#)
  	   ((memq ch '(60 ?<)) (w3m-scroll-right nil))
--- 325,359 ----
  		(unless (string-equal str "") ; delete last filter character
  		  (setq num 1
  			last-index
! 			(w3m-lnum
  			 type (setq str (w3m-substring-no-properties
  					 str 0 (1- (length str)))))
  			temp-prompt
! 			(w3m-lnum-prompt-str num fun prompt
! 					     def-anchor str "")))
  	      (setq num (/ num 10))	; delete last digit
  	      (if (zerop num)
  		  (setq num 1
  			auto-num t))
  	      (setq temp-prompt
! 		    (w3m-lnum-prompt-str num fun prompt
! 					 def-anchor str
! 					 (if auto-num "")))))
  	   ;; scroll options
  	   ((memq ch '(32 ?\ ))		; scroll down
! 	    (w3m-lnum-remove-overlays)
  	    (ignore-errors
  	      (w3m-scroll-up-1)
  	      (redisplay))   ; scroll-up sets wrongly window-start/end
  	    #1=
! 	    (setq last-index (w3m-lnum type str t)
  		  num (if (zerop last-index) 0 1)
  		  auto-num t
! 		  temp-prompt (w3m-lnum-prompt-str num fun prompt
! 						   def-anchor
! 						   str "")))
  	   ((eq ch 'delete)		; scroll up
! 	    (w3m-lnum-remove-overlays)
  	    (ignore-errors (scroll-down nil))
  	    #1#)
  	   ((memq ch '(60 ?<)) (w3m-scroll-right nil))
***************
*** 421,435 ****
  		(setq num (1- num)
  		      auto-num t
  		      temp-prompt
! 		      (w3m-linknum-prompt-str num fun prompt
! 					      def-anchor str ""))))
  	   ((memq ch '(right down))
  	    (if (< num last-index)
  		(setq num (1+ num)
  		      auto-num t
  		      temp-prompt
! 		      (w3m-linknum-prompt-str num fun prompt
! 					      def-anchor str ""))))
  	   ((and (w3m-static-if (featurep 'xemacs) ; digit
  		     (characterp ch)
  		   (numberp ch))
--- 364,378 ----
  		(setq num (1- num)
  		      auto-num t
  		      temp-prompt
! 		      (w3m-lnum-prompt-str num fun prompt
! 					   def-anchor str ""))))
  	   ((memq ch '(right down))
  	    (if (< num last-index)
  		(setq num (1+ num)
  		      auto-num t
  		      temp-prompt
! 		      (w3m-lnum-prompt-str num fun prompt
! 					   def-anchor str ""))))
  	   ((and (w3m-static-if (featurep 'xemacs) ; digit
  		     (characterp ch)
  		   (numberp ch))
***************
*** 444,456 ****
  		(if (zerop (setq num (/ num 10)))
  		    (setq num 1
  			  auto-num t))
! 	      (and (memq w3m-link-numbering-quick-browsing
  			 '(quick-all quick-numbers))
  		   (> (* num 10) last-index)
  		   (throw 'select num)))
  	    (setq temp-prompt
! 		  (w3m-linknum-prompt-str num fun prompt def-anchor
! 					  str (if auto-num ""))))
  	   (t (setq ch (string (w3m-static-if (featurep 'xemacs)
  				   (cond
  				    ((eq ch t) key)
--- 387,399 ----
  		(if (zerop (setq num (/ num 10)))
  		    (setq num 1
  			  auto-num t))
! 	      (and (memq w3m-lnum-quick-browsing
  			 '(quick-all quick-numbers))
  		   (> (* num 10) last-index)
  		   (throw 'select num)))
  	    (setq temp-prompt
! 		  (w3m-lnum-prompt-str num fun prompt def-anchor
! 				       str (if auto-num ""))))
  	   (t (setq ch (string (w3m-static-if (featurep 'xemacs)
  				   (cond
  				    ((eq ch t) key)
***************
*** 462,507 ****
  					(< ch 67108922))
  				   (- ch 67108864)) ; as NUMBER
  				  (t ch)))))
! 	      (setq last-index (w3m-link-numbering
! 				type (setq str (concat str ch))))
! 	      (if (and (memq w3m-link-numbering-quick-browsing
! 			     '(quick-all quick-filter))
! 		       (= last-index 1))
  		  (throw 'select (setq num 1))
  		(if (zerop last-index) ; filter left nothing, remove new char
  		    (setq last-index
! 			  (w3m-link-numbering
  			   type
  			   (setq str (w3m-substring-no-properties
! 				      str 0 (1- (length str)))))))
  		(setq num 1
  		      auto-num t
  		      temp-prompt
! 		      (w3m-linknum-prompt-str num fun prompt
! 					      def-anchor str "")))))))
        (if (memq ch '(?\C-g escape 27 ?\e))
  	  (keyboard-quit)))
      num))
  
! (defmacro w3m-with-linknum (type &rest body)
    "Within TYPE anchor numbering execute BODY.
  Types are: 0 no numbering, 1 links, 2 images, otherwise all anchors.
  Then clear numbering overlays.
! Within BODY, `last-index' is bound to the last used number."
!   `(unwind-protect (let ((last-index (w3m-link-numbering ,type)))
  		     ,@body)
!      (w3m-linknum-remove-overlays)))
  
! (defun w3m-highlight-numbered-anchor (arg)
    "Highlight specified by ARG number anchor.
  Return selected anchor."
    (let (newly-marked)
!     (dolist (overlay (overlays-in (max (1- (window-start)) (point-min))
  				  (window-end)))
        (cond
!        ((overlay-get overlay 'w3m-linknum-match)
  	(delete-overlay overlay))
!        ((eq arg (overlay-get overlay 'w3m-link-numbering-overlay))
  	(let* ((start (overlay-start overlay))
  	       (match-overlay
  		(make-overlay
--- 405,452 ----
  					(< ch 67108922))
  				   (- ch 67108864)) ; as NUMBER
  				  (t ch)))))
! 	      (setq last-index (w3m-lnum type
! 					 (setq str (concat str ch))))
! 	      (if (and (= last-index 1)
! 		       (memq w3m-lnum-quick-browsing
! 			     '(quick-all quick-filter)))
  		  (throw 'select (setq num 1))
  		(if (zerop last-index) ; filter left nothing, remove new char
  		    (setq last-index
! 			  (w3m-lnum
  			   type
  			   (setq str (w3m-substring-no-properties
! 				      str 0 (1- (length str))))
! 			   t)))
  		(setq num 1
  		      auto-num t
  		      temp-prompt
! 		      (w3m-lnum-prompt-str num fun prompt
! 					   def-anchor str "")))))))
        (if (memq ch '(?\C-g escape 27 ?\e))
  	  (keyboard-quit)))
      num))
  
! (defmacro w3m-with-lnum (type &rest body)
    "Within TYPE anchor numbering execute BODY.
  Types are: 0 no numbering, 1 links, 2 images, otherwise all anchors.
  Then clear numbering overlays.
! Within BODY, `last-index' is bound to the last used index number."
!   `(unwind-protect (let ((last-index (w3m-lnum ,type)))
  		     ,@body)
!      (w3m-lnum-remove-overlays)))
  
! (defun w3m-lnum-highlight-anchor (arg)
    "Highlight specified by ARG number anchor.
  Return selected anchor."
    (let (newly-marked)
!     (dolist (overlay (overlays-in (max (1- (window-start))
! 				       (point-min))
  				  (window-end)))
        (cond
!        ((overlay-get overlay 'w3m-lnum-match)
  	(delete-overlay overlay))
!        ((eq arg (overlay-get overlay 'w3m-lnum-overlay))
  	(let* ((start (overlay-start overlay))
  	       (match-overlay
  		(make-overlay
***************
*** 512,519 ****
  			 'w3m-anchor-sequence)
  			((w3m-image start) 'w3m-image)
  			(t 'w3m-action))))))
! 	  (overlay-put match-overlay 'w3m-linknum-match t)
! 	  (overlay-put match-overlay 'face 'w3m-linknum-match)
  	  (or newly-marked
  	      (setq newly-marked
  		    (or (w3m-anchor start)
--- 457,464 ----
  			 'w3m-anchor-sequence)
  			((w3m-image start) 'w3m-image)
  			(t 'w3m-action))))))
! 	  (overlay-put match-overlay 'w3m-lnum-match t)
! 	  (overlay-put match-overlay 'face 'w3m-lnum-match)
  	  (or newly-marked
  	      (setq newly-marked
  		    (or (w3m-anchor start)
***************
*** 523,529 ****
  				start 'w3m-action)))))))))
      newly-marked))
  
! (defmacro w3m-get-match-info (condition found-tag)
    "For the first overlay matching CONDITION throw through FOUND-TAG
  anchor info."
    `(dolist (overlay (overlays-in (max (1- (window-start)) (point-min))
--- 468,474 ----
  				start 'w3m-action)))))))))
      newly-marked))
  
! (defmacro w3m-lnum-get-match-info (condition found-tag)
    "For the first overlay matching CONDITION throw through FOUND-TAG
  anchor info."
    `(dolist (overlay (overlays-in (max (1- (window-start)) (point-min))
***************
*** 537,580 ****
  		    (list (w3m-action pos) pos (w3m-image pos)
  			  (w3m-image-alt pos))))))))
  
! (defun w3m-get-anchor-info (&optional num)
    "Get info (url/action position image image-alt) of anchor numbered as NUM.
  If NUM is not specified, use currently highlighted anchor."
    (catch 'found
!     (if num (w3m-get-match-info
! 	     (eq num
! 		 (overlay-get overlay 'w3m-link-numbering-overlay))
  	     'found)
!       (w3m-get-match-info (overlay-get overlay 'w3m-linknum-match)
! 			  'found))))
  
! ;;;###autoload
! (defun w3m-go-to-linknum (arg)
!   "Turn on link, image and form numbers and ask for one to go to.
! With prefix ARG don't highlight current link.
! 0 corresponds to location url."
!   (interactive "P")
!   (w3m-with-linknum
!    3
!    (let ((info (if arg
! 		   (let ((num (w3m-read-number "Anchor number: ")))
! 		     (if (zerop num)
! 			 (list nil 16)
! 		       (w3m-get-anchor-info num)))
! 		 (let ((num (w3m-read-int-interactive
! 			     "Anchor number: "
! 			     'w3m-highlight-numbered-anchor
! 			     3
! 			     last-index
! 			     w3m-current-url)))
! 		   (if (zerop num)
! 		       (list nil 16)
! 		     (w3m-get-anchor-info num))))))
!      (if info (progn (push-mark (point))
! 		     (goto-char (cadr info)))
!        (w3m-message "No valid anchor selected")))))
! 
! (defun w3m-linknum-get-action (&optional prompt type)
    "Turn on link numbers and return list of url or action, position and
  image url if such of PROMPT selected anchor.
  TYPE sets types of anchors to be numbered: 0 - no numbering,
--- 482,498 ----
  		    (list (w3m-action pos) pos (w3m-image pos)
  			  (w3m-image-alt pos))))))))
  
! (defun w3m-lnum-get-anchor-info (&optional num)
    "Get info (url/action position image image-alt) of anchor numbered as NUM.
  If NUM is not specified, use currently highlighted anchor."
    (catch 'found
!     (if num (w3m-lnum-get-match-info
! 	     (eq num (overlay-get overlay 'w3m-lnum-overlay))
  	     'found)
!       (w3m-lnum-get-match-info (overlay-get overlay 'w3m-lnum-match)
! 			       'found))))
  
! (defun w3m-lnum-get-action (&optional prompt type)
    "Turn on link numbers and return list of url or action, position and
  image url if such of PROMPT selected anchor.
  TYPE sets types of anchors to be numbered: 0 - no numbering,
***************
*** 582,601 ****
  Highlight every intermediate result anchor.
  Input 0 corresponds to location url."
    (setq type (or type 3))
!   (w3m-with-linknum
     type
!    (let ((num (w3m-read-int-interactive (or prompt "Anchor number: ")
! 					'w3m-highlight-numbered-anchor
! 					type last-index
! 					(unless (= type 2)
! 					  w3m-current-url))))
!      (if (and (zerop num)
! 	      (not (= type 2)))
! 	 (list w3m-current-url 16 nil nil)
!        (w3m-get-anchor-info num)))))
  
  ;;;###autoload
! (defun w3m-linknum-follow (arg)
    "Turn on link numbers, ask for one and execute appropriate action on it.
  If link - visit it, when button - press, when input - activate it,
  If image - toggle it.
--- 500,536 ----
  Highlight every intermediate result anchor.
  Input 0 corresponds to location url."
    (setq type (or type 3))
!   (w3m-with-lnum
     type
!    (if (and (zerop last-index)
! 	    (not (= type 2)))
!        (if (y-or-n-p (concat "No items found. Select default? ["
! 			     w3m-current-url "] "))
! 	   (list w3m-current-url 16 nil nil)
! 	 (keyboard-quit))
!      (let ((num (w3m-lnum-read-interactive (or prompt
! 					       "Anchor number: ")
! 					   'w3m-lnum-highlight-anchor
! 					   type last-index
! 					   (unless (= type 2)
! 					     w3m-current-url))))
!        (if (and (zerop num)
! 		(not (= type 2)))
! 	   (list w3m-current-url 16 nil nil)
! 	 (w3m-lnum-get-anchor-info num))))))
! 
! ;;;###autoload
! (defun w3m-lnum-goto ()
!   "Turn on link, image and form numbers and ask for one to go to.
! 0 corresponds to location url."
!   (interactive)
!   (let ((info (w3m-lnum-get-action)))
!     (if info (progn (push-mark (point))
! 		    (goto-char (cadr info)))
!       (w3m-message "No valid anchor selected"))))
  
  ;;;###autoload
! (defun w3m-lnum-follow (arg)
    "Turn on link numbers, ask for one and execute appropriate action on it.
  If link - visit it, when button - press, when input - activate it,
  If image - toggle it.
***************
*** 606,612 ****
  With double prefix ARG, prompt for url to visit.
  With triple prefix ARG, prompt for url to visit in new session."
    (interactive "p")
!   (let ((info (w3m-linknum-get-action
  	       (concat "Follow " (if (> arg 1) "in new session ")
  		       "(select anchor): "))))
      (if info
--- 541,547 ----
  With double prefix ARG, prompt for url to visit.
  With triple prefix ARG, prompt for url to visit in new session."
    (interactive "p")
!   (let ((info (w3m-lnum-get-action
  	       (concat "Follow " (if (> arg 1) "in new session ")
  		       "(select anchor): "))))
      (if info
***************
*** 659,668 ****
        (w3m-message "No valid anchor selected"))))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
! ;;; linknum alternatives to w3m user commands on point
  
  ;;;###autoload
! (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 url under image in new session.
--- 594,603 ----
        (w3m-message "No valid anchor selected"))))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
! ;;; lnum alternatives to w3m user commands on point
  
  ;;;###autoload
! (defun w3m-lnum-toggle-inline-image (&optional arg)
    "If image at point, toggle it.
  Otherwise turn on link numbers and toggle selected image.
  With prefix ARG open url under image in new session.
***************
*** 673,679 ****
  	(if (and arg url)
  	    (w3m-goto-url-new-session url)
  	  (w3m-toggle-inline-image)))
!     (let ((im (w3m-linknum-get-action
  	       (if arg "Open image url in new session: "
  		 "Toggle image: ")
  	       2)))
--- 608,614 ----
  	(if (and arg url)
  	    (w3m-goto-url-new-session url)
  	  (w3m-toggle-inline-image)))
!     (let ((im (w3m-lnum-get-action
  	       (if arg "Open image url in new session: "
  		 "Toggle image: ")
  	       2)))
***************
*** 688,694 ****
  	(w3m-message "No image selected")))))
  
  ;;;###autoload
! (defun w3m-linknum-view-image ()
    "Display the image under point in the external viewer.
  If no image at poing, turn on image numbers and display selected.
  The viewer is defined in `w3m-content-type-alist' for every type of an
--- 623,629 ----
  	(w3m-message "No image selected")))))
  
  ;;;###autoload
! (defun w3m-lnum-view-image ()
    "Display the image under point in the external viewer.
  If no image at poing, turn on image numbers and display selected.
  The viewer is defined in `w3m-content-type-alist' for every type of an
***************
*** 696,719 ****
    (interactive)
    (let ((im (w3m-url-valid (w3m-image))))
      (cond (im (w3m-external-view im))
! 	  ((setq im (w3m-linknum-get-action
  		     "Open image url in external viewer: " 2))
  	   (w3m-external-view (car (cddr im))))
  	  (t (w3m-message "No image selected")))))
  
  ;;;###autoload
! (defun w3m-linknum-save-image ()
    "Save the image under point to a file.
  If no image at poing, turn on image numbers and save selected.
  The default name will be the original name of the image."
    (interactive)
    (let ((im (w3m-url-valid (w3m-image))))
      (cond (im (w3m-download im))
! 	  ((setq im (w3m-linknum-get-action "Save image: " 2))
  	   (w3m-download (car (cddr im))))
  	  (t (w3m-message "No image selected")))))
  
! (defmacro w3m-linknum-zoom-image (rate &optional in)
    "Zoom image under the point.
  Numeric prefix RATE specifies how many percent the image is
  changed by.  Default is the value of the `w3m-resize-image-scale'
--- 631,654 ----
    (interactive)
    (let ((im (w3m-url-valid (w3m-image))))
      (cond (im (w3m-external-view im))
! 	  ((setq im (w3m-lnum-get-action
  		     "Open image url in external viewer: " 2))
  	   (w3m-external-view (car (cddr im))))
  	  (t (w3m-message "No image selected")))))
  
  ;;;###autoload
! (defun w3m-lnum-save-image ()
    "Save the image under point to a file.
  If no image at poing, turn on image numbers and save selected.
  The default name will be the original name of the image."
    (interactive)
    (let ((im (w3m-url-valid (w3m-image))))
      (cond (im (w3m-download im))
! 	  ((setq im (w3m-lnum-get-action "Save image: " 2))
  	   (w3m-download (car (cddr im))))
  	  (t (w3m-message "No image selected")))))
  
! (defmacro w3m-lnum-zoom-image (rate &optional in)
    "Zoom image under the point.
  Numeric prefix RATE specifies how many percent the image is
  changed by.  Default is the value of the `w3m-resize-image-scale'
***************
*** 729,735 ****
  	(im (w3m-resize-inline-image-internal
  	     im
  	     (,(if in '+ '-) 100 (or ,rate w3m-resize-image-scale))))
! 	((setq im (w3m-linknum-get-action
  		   ,(concat "Zoom " (if in "in" "out") " image: ") 2))
  	 (save-excursion
  	   (goto-char (cadr im))
--- 664,670 ----
  	(im (w3m-resize-inline-image-internal
  	     im
  	     (,(if in '+ '-) 100 (or ,rate w3m-resize-image-scale))))
! 	((setq im (w3m-lnum-get-action
  		   ,(concat "Zoom " (if in "in" "out") " image: ") 2))
  	 (save-excursion
  	   (goto-char (cadr im))
***************
*** 738,792 ****
  	    (,(if in '+ '-) 100 (or ,rate w3m-resize-image-scale)))))
  	(t (w3m-message "No image at point"))))))
  
! (defun w3m-linknum-zoom-in-image (&optional rate)
    "Zoom in an image on the point.
  Numeric prefix RATE specifies how many percent the image is
  enlarged by \(30 means enlarging the image by 130%).  The default
  is the value of the `w3m-resize-image-scale' variable.  If no
  image under point, activate numbering and ask for one."
    (interactive "P")
!   (w3m-linknum-zoom-image rate t))
  
! (defun w3m-linknum-zoom-out-image (&optional rate)
    "Zoom out an image on the point.
  Numeric prefix RATE specifies how many percent the image is shrunk by
  \(30 means shrinking the image by 70%).  The default is the value of
  the `w3m-resize-image-scale' variable.
  If no image under point, activate numbering and ask for one."
    (interactive "P")
!   (w3m-linknum-zoom-image rate))
  
  ;;;###autoload
! (defun w3m-linknum-external-view-this-url ()
    "Launch the external browser and display the link at point.
  If no link at point, turn on link numbers and open selected externally."
    (interactive)
    (let ((url (w3m-url-valid (or (w3m-anchor) (w3m-image)
  				(car
! 				 (w3m-linknum-get-action
  				  "Open in external browser: " 1))))))
      (if url (w3m-external-view url)
        (w3m-message "No URL selected"))))
  
  ;;;###autoload
! (defun w3m-linknum-edit-this-url ()
    "Edit the page linked from the anchor under the cursor.
  If no such, turn on link numbers and edit selected."
    (interactive)
    (let ((url (or (w3m-url-valid (w3m-anchor))
! 		 (car (w3m-linknum-get-action
  		       "Select link to edit: " 1)))))
      (if url (w3m-edit-url url)
        (w3m-message "No URL selected"))))
  
  ;;;###autoload
! (defun w3m-linknum-print-this-url ()
    "Display the url under point in the echo area and put it into `kill-ring'.
  If no url under point, activate numbering and select one."
    (interactive)
    (if (or (w3m-anchor) (w3m-image))
        (w3m-print-this-url t)
!     (let ((link (w3m-linknum-get-action "Select URL to copy: " 1)))
        (if link
  	  (let ((url (car link)))
  	    (kill-new url)
--- 673,727 ----
  	    (,(if in '+ '-) 100 (or ,rate w3m-resize-image-scale)))))
  	(t (w3m-message "No image at point"))))))
  
! (defun w3m-lnum-zoom-in-image (&optional rate)
    "Zoom in an image on the point.
  Numeric prefix RATE specifies how many percent the image is
  enlarged by \(30 means enlarging the image by 130%).  The default
  is the value of the `w3m-resize-image-scale' variable.  If no
  image under point, activate numbering and ask for one."
    (interactive "P")
!   (w3m-lnum-zoom-image rate t))
  
! (defun w3m-lnum-zoom-out-image (&optional rate)
    "Zoom out an image on the point.
  Numeric prefix RATE specifies how many percent the image is shrunk by
  \(30 means shrinking the image by 70%).  The default is the value of
  the `w3m-resize-image-scale' variable.
  If no image under point, activate numbering and ask for one."
    (interactive "P")
!   (w3m-lnum-zoom-image rate))
  
  ;;;###autoload
! (defun w3m-lnum-external-view-this-url ()
    "Launch the external browser and display the link at point.
  If no link at point, turn on link numbers and open selected externally."
    (interactive)
    (let ((url (w3m-url-valid (or (w3m-anchor) (w3m-image)
  				(car
! 				 (w3m-lnum-get-action
  				  "Open in external browser: " 1))))))
      (if url (w3m-external-view url)
        (w3m-message "No URL selected"))))
  
  ;;;###autoload
! (defun w3m-lnum-edit-this-url ()
    "Edit the page linked from the anchor under the cursor.
  If no such, turn on link numbers and edit selected."
    (interactive)
    (let ((url (or (w3m-url-valid (w3m-anchor))
! 		 (car (w3m-lnum-get-action
  		       "Select link to edit: " 1)))))
      (if url (w3m-edit-url url)
        (w3m-message "No URL selected"))))
  
  ;;;###autoload
! (defun w3m-lnum-print-this-url ()
    "Display the url under point in the echo area and put it into `kill-ring'.
  If no url under point, activate numbering and select one."
    (interactive)
    (if (or (w3m-anchor) (w3m-image))
        (w3m-print-this-url t)
!     (let ((link (w3m-lnum-get-action "Select URL to copy: " 1)))
        (if link
  	  (let ((url (car link)))
  	    (kill-new url)
***************
*** 797,809 ****
  	(w3m-message "No URL selected")))))
  
  ;;;###autoload
! (defun w3m-linknum-download-this-url ()
    "Download the file or the page pointed to by the link under point.
  If no point, activate numbering and select andchor to download."
    (interactive)
    (if (or (w3m-anchor) (w3m-image) (w3m-action))
        (w3m-download-this-url)
!     (let ((info (w3m-linknum-get-action
  		 "Select anchor to download: ")))
        (if info
  	  (save-excursion
--- 732,744 ----
  	(w3m-message "No URL selected")))))
  
  ;;;###autoload
! (defun w3m-lnum-download-this-url ()
    "Download the file or the page pointed to by the link under point.
  If no point, activate numbering and select andchor to download."
    (interactive)
    (if (or (w3m-anchor) (w3m-image) (w3m-action))
        (w3m-download-this-url)
!     (let ((info (w3m-lnum-get-action
  		 "Select anchor to download: ")))
        (if info
  	  (save-excursion
***************
*** 812,818 ****
  	(w3m-message "No anchor selected")))))
  
  ;;;###autoload
! (defun w3m-linknum-bookmark-add-this-url ()
    "Add link under cursor to bookmark.
  If no link under point, activate numbering and ask for one."
    (interactive)
--- 747,753 ----
  	(w3m-message "No anchor selected")))))
  
  ;;;###autoload
! (defun w3m-lnum-bookmark-add-this-url ()
    "Add link under cursor to bookmark.
  If no link under point, activate numbering and ask for one."
    (interactive)
***************
*** 825,831 ****
  					     'w3m-href-anchor)
  	    (next-single-property-change (point) 'w3m-href-anchor)))
  	  (message "Added"))
!      ((setq url (w3m-linknum-get-action "Select URL to bookmark: " 1))
        (w3m-bookmark-add
         (car url)
         (buffer-substring-no-properties
--- 760,766 ----
  					     'w3m-href-anchor)
  	    (next-single-property-change (point) 'w3m-href-anchor)))
  	  (message "Added"))
!      ((setq url (w3m-lnum-get-action "Select URL to bookmark: " 1))
        (w3m-bookmark-add
         (car url)
         (buffer-substring-no-properties