[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] w3m-lnum add highlight
- From: Katsumi Yamaoka <yamaoka@xxxxxxx>
- Date: Mon, 05 Jul 2010 08:14:25 +0900
- X-ml-name: emacs-w3m
- X-mail-count: 11252
- References: <87630wfds0.fsf@xxxxxxxxx>
In [emacs-w3m : No.11251] Andrey Kotlarski wrote:
(B> I enjoy both Conkeror and emacs-w3m and was quite happy to discover
(B> w3m-lnum which gives emacs-w3m one of the nicest features of Conkeror.
(B> One thing seems to be missing though, highlighting of the to be selected
(B> numbered anchor, so here's what I've come up with (don't use XEmacs so
(B> feel free to add what's needed to properly set overlay face).
(BThank you for the patch. I tried it (ignoring spurious diffs, and
(Brenaming read-int-interactive into w3m-read-int-interactive; see
(Bthe new diff attached below). However, there is one problem that
(Bstops it working. What is `right-char'? That can be found in
(B2010-07-04 Andrey Kotlarski <m00naticus@xxxxxxxxx>
(B * w3m-lnum.el: Update usage comment.
(B (w3m-link-numbering-mode): Delete w3m-current-linknum overlay as well.
(B (w3m-move-numbered-anchor): Fix grammar in error message.
(B (w3m-go-to-linknum): Add autoload cookie.
(B (w3m-read-int-interactive, w3m-highlight-numbered-anchor)
(B (w3m-view-linknum): New functions.
--- w3m-lnum.el~ 2009-02-24 06:58:26 +0000
(B+++ w3m-lnum.el 2010-07-04 22:49:40 +0000
(B@@ -1,6 +1,6 @@
(B ;;; w3m-lnum.el --- Operations using link numbers
(B-;; Copyright (C) 2004, 2005, 2006, 2007, 2009
(B+;; Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010
(B ;; TSUCHIYA Masatoshi <tsuchiya@xxxxxxxxxx>
(B ;; Authors: TSUCHIYA Masatoshi <tsuchiya@xxxxxxxxxx>
(B@@ -34,6 +34,7 @@
(B ;; expressions to your ~/.emacs-w3m.
(B ;; (autoload 'w3m-link-numbering-mode "w3m-lnum" nil t)
(B+;; (autoload 'w3m-view-linknum "w3m-lnum" nil t)
(B ;; (add-hook 'w3m-mode-hook 'w3m-link-numbering-mode)
(B ;;; Code:
(B@@ -84,7 +85,8 @@
(B (run-hooks 'w3m-link-numbering-mode-hook))
(B (dolist (overlay (overlays-in (point-min) (point-max)))
(B- (when (overlay-get overlay 'w3m-link-numbering-overlay)
(B+ (when (or (overlay-get overlay 'w3m-link-numbering-overlay)
(B+ (overlay-get overlay 'w3m-current-linknum))
(B (delete-overlay overlay)))))
(B (defun w3m-link-numbering (&rest args)
(B@@ -125,9 +127,10 @@
(B (push (w3m-anchor-sequence) w3m-goto-anchor-hist)
(B (throw 'found (w3m-print-this-url))))
(B- (error "Cannot found your specified link: %d" arg))
(B+ (error "Cannot find specified link: %d" arg))
(B (defun w3m-go-to-linknum ()
(B "Turn on link numbers and ask for one to go to."
(B@@ -139,6 +142,69 @@
(B (unless active
(B (w3m-link-numbering-mode 0)))))
(B+(defun w3m-read-int-interactive (prompt fun &optional default)
(B+ "Interactively read a valid integer from minubuffer with PROMPT.
(B+Execute a one argument FUNCTION with every current valid integer.
(B+Initial value is DEFAULT if specified or 0.
(B+Use <return> to submit current value and <backspace> for correction."
(B+ (let ((prompt (propertize prompt 'face 'minibuffer-prompt))
(B+ (num (or default 0))
(B+ (min-len (length prompt))
(B+ (let ((temp-prompt (format "%s%d" prompt num)))
(B+ (while (not (eq (setq ch (read-event temp-prompt)) 'return))
(B+ (cond ((and (eq ch 'backspace)
(B+ (> (length temp-prompt) min-len))
(B+ (setq num (/ num 10)
(B+ temp-prompt (format "%s%d" prompt num))
(B+ (funcall fun num))
(B+ ((and (numberp ch) (> ch 47) (< ch 58))
(B+ (setq num (+ (* num 10) (- ch 48))
(B+ temp-prompt (format "%s%d" prompt num))
(B+ (funcall fun num))))
(B+(defun w3m-highlight-numbered-anchor (arg)
(B+ "Highlight specified by ARG number anchor."
(B+ (catch 'done
(B+ (let (found-prev marked-new)
(B+ (dolist (overlay (overlays-in (point-min) (point-max)))
(B+ ((and found-prev marked-new)
(B+ (throw 'done nil))
(B+ ((overlay-get overlay 'w3m-current-linknum)
(B+ (delete-overlay overlay)
(B+ (setq found-prev t))
(B+ ((eq arg (overlay-get overlay 'w3m-link-numbering-overlay))
(B+ (let ((start (overlay-start overlay)))
(B+ (goto-char start)
(B+ (let ((anchor (w3m-anchor)))
(B+ (while (equal anchor
(B+ (get-text-property (point)
(B+ (let ((curr-overlay (make-overlay start (point))))
(B+ (overlay-put curr-overlay 'w3m-current-linknum t)
(B+ (overlay-put curr-overlay 'face 'match))))
(B+ (setq marked-new t)))))))
(B+(defun w3m-view-linknum (arg)
(B+ "Turn on link numbers, ask for one and follow it.
(B+With prefix ARG just move over it.
(B+Whenever valid minibuffer input, highlight corespondent link."
(B+ (interactive "P")
(B+ (let ((active w3m-link-numbering-mode))
(B+ (or active (w3m-link-numbering-mode 1))
(B+ (w3m-read-int-interactive "Anchor number: "
(B+ (or active (w3m-link-numbering-mode 0))))
(B+ (or arg (w3m-view-this-url)))
(B (provide 'w3m-lnum)
(B ;;; w3m-lnum.el ends here