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

[PATCH] w3m-lnum.el: something new, something old, something blue



Hello, here come some fixes and new additions to keep in tact with
eww-lnum.el.  Changelog entry follows and then the diff.

2014-11-24  Andrey Kotlarski  <m00naticus@xxxxxxxxx>

	* w3m-lnum.el (w3m-lnum-actions-link-alist): Add open in background
	bindings.
	(w3m-lnum-remove-overlays): Enlarge default region to clean.
	(w3m-lnum-set-numbering): Use w3m-lnum-remove-overlays.
	(w3m-lnum-next-filter): New function.
	(w3m-lnum-read-interactive): Use it to search below and above when
	filter has no matches left.
	(w3m-with-lnum): Guarantee cleanup of right buffer.
	(w3m-lnum-get-action): Fix checkdoc warning.
	(w3m-lnum-visit): Make it function.  Enable visiting in background.
	(w3m-lnum-follow): Add prefix combinations to visit links in
	background.

---
Index: w3m-lnum.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-lnum.el,v
retrieving revision 1.45
diff -c -r1.45 w3m-lnum.el
*** w3m-lnum.el	17 Oct 2013 01:33:17 -0000	1.45
--- w3m-lnum.el	24 Nov 2014 21:28:02 -0000
***************
*** 1,6 ****
  ;;; w3m-lnum.el --- Operations using link numbers
  
! ;; Copyright (C) 2004-2013 TSUCHIYA Masatoshi <tsuchiya@xxxxxxxxxx>
  
  ;; Authors: TSUCHIYA Masatoshi <tsuchiya@xxxxxxxxxx>
  ;;          Andrey Kotlarski <m00naticus@xxxxxxxxx>
--- 1,6 ----
  ;;; w3m-lnum.el --- Operations using link numbers
  
! ;; Copyright (C) 2004-2014 TSUCHIYA Masatoshi <tsuchiya@xxxxxxxxxx>
  
  ;; Authors: TSUCHIYA Masatoshi <tsuchiya@xxxxxxxxxx>
  ;;          Andrey Kotlarski <m00naticus@xxxxxxxxx>
***************
*** 134,147 ****
  (defcustom w3m-lnum-actions-link-alist
    '("----  Link   ----"
      (?g (lambda (info) (w3m-lnum-visit info)) "Visit")
!     (?G (lambda (info) (setq mode-line-format original-mode-line-format)
! 	  (w3m-lnum-remove-overlays)
! 	  (w3m-lnum-visit info t)) "Visit in new session")
      (?v (lambda (info) (w3m-lnum-visit info nil t)) "Edit and visit")
!     (?V (lambda (info) (setq mode-line-format original-mode-line-format)
! 	  (w3m-lnum-remove-overlays)
! 	  (w3m-lnum-visit info t t))
  	"Edit and visit in new session")
      (?e (lambda (info) (w3m-edit-url (car info))) "Edit page")
      (?s (lambda (info) (save-excursion
  		    (goto-char (cadr info))
--- 134,147 ----
  (defcustom w3m-lnum-actions-link-alist
    '("----  Link   ----"
      (?g (lambda (info) (w3m-lnum-visit info)) "Visit")
!     (?G (lambda (info) (w3m-lnum-visit info t)) "Visit in new session")
!     (?B (lambda (info) (w3m-lnum-visit info :background))
! 	"Visit in background")
      (?v (lambda (info) (w3m-lnum-visit info nil t)) "Edit and visit")
!     (?V (lambda (info) (w3m-lnum-visit info t t))
  	"Edit and visit in new session")
+     (?& (lambda (info) (w3m-lnum-visit info :background t))
+ 	"Edit url and visit in background")
      (?e (lambda (info) (w3m-edit-url (car info))) "Edit page")
      (?s (lambda (info) (save-excursion
  		    (goto-char (cadr info))
***************
*** 236,243 ****
  (defun w3m-lnum-remove-overlays (&optional start end)
    "Remove numbering and match overlays between START and END points.
  If missing, clear the current visible window."
!   (let ((start (or start (max (1- (window-start)) (point-min))))
! 	(end (or end (min (window-end) (point-max)))))
      (dolist (overlay (overlays-in start end))
        (if (or (overlay-get overlay 'w3m-lnum-overlay)
  	      (overlay-get overlay 'w3m-lnum-match))
--- 236,247 ----
  (defun w3m-lnum-remove-overlays (&optional start end)
    "Remove numbering and match overlays between START and END points.
  If missing, clear the current visible window."
!   (let* ((start-pos (window-start))
! 	 (window-size (- (window-end) start-pos))
! 	 (start (or start (max (- start-pos window-size)
! 			       (point-min))))
! 	 (end (or end (min (+ start-pos (* 2 window-size))
! 			   (point-max)))))
      (dolist (overlay (overlays-in start end))
        (if (or (overlay-get overlay 'w3m-lnum-overlay)
  	      (overlay-get overlay 'w3m-lnum-match))
***************
*** 310,328 ****
  	     "\\$" "\\\\$")
  	  "")
  	next-func (or next-func 'w3m-goto-next-anchor-or-image))
    (let ((pos (max (1- (window-start)) (point-min)))
! 	(pmax (min (window-end) (point-max))))
!     (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))
  		  (< pos pmax))
  	(let ((str ""))
  	  (let ((hseq (get-char-property pos 'w3m-anchor-sequence)))
--- 314,381 ----
  	     "\\$" "\\\\$")
  	  "")
  	next-func (or next-func 'w3m-goto-next-anchor-or-image))
+   (or dont-clear-p
+       (w3m-lnum-remove-overlays))
    (let ((pos (max (1- (window-start)) (point-min)))
! 	(pmax (min (window-end) (point-max)))
! 	(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))
! 		(< pos pmax))
!       (let ((str ""))
! 	(let ((hseq (get-char-property pos 'w3m-anchor-sequence)))
! 	  (if hseq			; multiline anchors
! 	      (let ((pos2 (next-single-property-change
! 			   pos 'w3m-anchor-sequence)))
! 		(while (and pos2
! 			    (setq pos2 (text-property-any
! 					pos2 pmax
! 					'w3m-anchor-sequence hseq)))
! 		  (let ((pos3 pos2))
! 		    (if (setq pos2 (next-single-property-change
! 				    pos2 'w3m-anchor-sequence))
! 			(setq str
! 			      (concat str
! 				      (buffer-substring-no-properties
! 				       pos3 pos2)))))))))
! 	(when (w3m-string-match-p reg
! 				  (concat
! 				   (buffer-substring-no-properties
! 				    pos
! 				    (next-single-property-change
! 				     pos
! 				     (cond ((w3m-anchor-sequence pos)
! 					    'w3m-anchor-sequence)
! 					   ((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-next-filter (type filter pmin pmax)
!   "Search next element according to TYPE and FILTER.
! Do this in region between points PMIN and PMAX.
! If such element is found, return its position.  Nil otherwise."
!   (setq filter
! 	(w3m-replace-regexps-in-string	; escape special characters
! 	 filter "\\?" "\\\\?" "\\!" "\\\\!" "\\[" "\\\\["
! 	 "\\*" "\\\\*" "\\+" "\\\\+" "\\." "\\\\." "\\^" "\\\\^"
! 	 "\\$" "\\\\$"))
!   (let ((pos pmin)
! 	(next-func (cond ((= type 1) 'w3m-goto-next-link)
! 			 ((= type 2) 'w3m-goto-next-image2)
! 			 (t 'w3m-goto-next-anchor-or-image))))
!     (catch 'found
!       (while (and pos (setq pos (funcall next-func pos))
  		  (< pos pmax))
  	(let ((str ""))
  	  (let ((hseq (get-char-property pos 'w3m-anchor-sequence)))
***************
*** 340,363 ****
  				(concat str
  					(buffer-substring-no-properties
  					 pos3 pos2)))))))))
! 	  (when (w3m-string-match-p reg
! 				    (concat
! 				     (buffer-substring-no-properties
! 				      pos
! 				      (next-single-property-change
! 				       pos
! 				       (cond ((w3m-anchor-sequence pos)
! 					      'w3m-anchor-sequence)
! 					     ((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 filter dont-clear-p)
    "Make overlays that display link numbers.  Return last used index.
--- 393,410 ----
  				(concat str
  					(buffer-substring-no-properties
  					 pos3 pos2)))))))))
! 	  (if (w3m-string-match-p filter
! 				  (concat
! 				   (buffer-substring-no-properties
! 				    pos
! 				    (next-single-property-change
! 				     pos
! 				     (cond ((w3m-anchor-sequence pos)
! 					    'w3m-anchor-sequence)
! 					   ((w3m-image pos)
! 					    'w3m-image))))
! 				   str))
! 	      (throw 'found pos)))))))
  
  (defun w3m-lnum (arg &optional filter dont-clear-p)
    "Make overlays that display link numbers.  Return last used index.
***************
*** 445,456 ****
  	      (if auto-num
  		  (unless (string-equal filter "") ; delete last filter character
  		    (setq num 1
! 			  last-index
! 			  (w3m-lnum
! 			   type (setq filter
! 				      (w3m-substring-no-properties
! 				       filter 0
! 				       (1- (length filter)))))
  			  temp-prompt
  			  (w3m-lnum-prompt-str num fun prompt
  					       def-anchor filter "")))
--- 492,500 ----
  	      (if auto-num
  		  (unless (string-equal filter "") ; delete last filter character
  		    (setq num 1
! 			  filter (w3m-substring-no-properties
! 				  filter 0 (1- (length filter)))
! 			  last-index (w3m-lnum type filter)
  			  temp-prompt
  			  (w3m-lnum-prompt-str num fun prompt
  					       def-anchor filter "")))
***************
*** 531,552 ****
  				    ((and (< 67108911 ch) ;treat <ctrl>+DIGIT
  					  (< ch 67108922))
  				     (- ch 67108864)) ; as DIGIT
! 				    (t ch)))))
! 		(setq last-index (w3m-lnum type
! 					   (setq filter
! 						 (concat filter 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 filter (w3m-substring-no-properties
! 					   filter 0
! 					   (1- (length filter))))
! 			     t)))
  		  (setq num 1
  			auto-num t
  			temp-prompt
--- 575,607 ----
  				    ((and (< 67108911 ch) ;treat <ctrl>+DIGIT
  					  (< ch 67108922))
  				     (- ch 67108864)) ; as DIGIT
! 				    (t ch))))
! 		      filter (concat filter ch)
! 		      last-index (w3m-lnum type filter))
  		(if (and (= last-index 1)
  			 (memq w3m-lnum-quick-browsing
  			       '(quick-all quick-filter)))
  		    (throw 'select (setq num 1))
! 		  (when (zerop last-index) ; filter left nothing
! 		    (let* ((pmax (point-max))
! 			   (pos (or (w3m-lnum-next-filter ;search below
! 				     type filter
! 				     (min (window-end) pmax) pmax)
! 				    (w3m-lnum-next-filter ;search above
! 				     type filter
! 				     (point-min) (window-start)))))
! 		      (when pos
! 			(goto-char pos)
! 			(if (and (fboundp 'redisplay)
! 				 (not (eq (symbol-function 'redisplay)
! 					  'ignore)))
! 			    (redisplay)
! 			  (sit-for 0))
! 			(setq last-index (w3m-lnum type filter t))))
! 		    (if (zerop last-index) ; search found nothing, remove new char
! 			(setq filter (w3m-substring-no-properties
! 				      filter 0 (1- (length filter)))
! 			      last-index (w3m-lnum type filter t))))
  		  (setq num 1
  			auto-num t
  			temp-prompt
***************
*** 561,567 ****
  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."
!   `(let ((original-mode-line-format mode-line-format))
       (unwind-protect (progn
  		       (setq mode-line-format
  			     "RET: select | BACKSPACE: correction | \
--- 616,623 ----
  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."
!   `(let ((original-mode-line-format mode-line-format)
! 	 (buffer (current-buffer)))
       (unwind-protect (progn
  		       (setq mode-line-format
  			     "RET: select | BACKSPACE: correction | \
***************
*** 571,578 ****
  		       (w3m-force-mode-line-update)
  		       (let ((last-index (w3m-lnum ,type ,filter)))
  			 ,@body))
!        (setq mode-line-format original-mode-line-format)
!        (w3m-lnum-remove-overlays))))
  
  (defun w3m-lnum-highlight-anchor (arg)
    "Highlight specified by ARG number anchor.
--- 627,635 ----
  		       (w3m-force-mode-line-update)
  		       (let ((last-index (w3m-lnum ,type ,filter)))
  			 ,@body))
!        (with-current-buffer buffer
! 	 (setq mode-line-format original-mode-line-format)
! 	 (w3m-lnum-remove-overlays (point-min) (point-max))))))
  
  (defun w3m-lnum-highlight-anchor (arg)
    "Highlight specified by ARG number anchor.
***************
*** 642,648 ****
     type ""
     (if (and (= type 2)			; image lack of selection
  	    (= last-index 1))
!        (if (y-or-n-p "Single image found. Select it?")
  	   (w3m-lnum-get-anchor-info 1))
       (if (and (zerop last-index)
  	      (not (= type 2)))
--- 699,705 ----
     type ""
     (if (and (= type 2)			; image lack of selection
  	    (= last-index 1))
!        (if (y-or-n-p "Single image found.  Select it? ")
  	   (w3m-lnum-get-anchor-info 1))
       (if (and (zerop last-index)
  	      (not (= type 2)))
***************
*** 670,691 ****
  		    (goto-char (cadr info)))
        (w3m-message "No valid anchor selected"))))
  
! (defmacro w3m-lnum-visit (info &optional new-session edit)
    "Visit URL determined with selection INFO.
! If NEW-SESSION, visit in new buffer.
  If EDIT, edit URL before visiting."
!   (if new-session
!       `(w3m-goto-url-new-session
! 	,(if edit `(read-string "Visit url in new session: "
! 				(car ,info))
! 	   `(car ,info)))
!     `(progn (push-mark (point))
! 	    (goto-char (cadr ,info))
! 	    (w3m-history-store-position)
! 	    (w3m-goto-url
! 	     ,(if edit `(read-string "Visit url: "
! 				     (car ,info))
! 		`(car ,info))))))
  
  ;;;###autoload
  (defun w3m-lnum-follow (arg)
--- 727,754 ----
  		    (goto-char (cadr info)))
        (w3m-message "No valid anchor selected"))))
  
! (defun w3m-lnum-visit (info &optional new-session edit)
    "Visit URL determined with selection INFO.
! If NEW-SESSION, visit in new buffer, optionally in `:background'.
  If EDIT, edit URL before visiting."
!   (cond ((eq new-session :background)
! 	 (save-window-excursion
! 	   (w3m-goto-url-new-session
! 	    (if edit (read-string "Visit url in new session: "
! 				  (car info))
! 	      (car info)))))
! 	(new-session
! 	 (w3m-goto-url-new-session
! 	  (if edit (read-string "Visit url in new session: "
! 				(car info))
! 	    (car info))))
! 	(t (push-mark (point))
! 	   (goto-char (cadr info))
! 	   (w3m-history-store-position)
! 	   (w3m-goto-url
! 	    (if edit (read-string "Visit url: "
! 				  (car info))
! 	      (car info))))))
  
  ;;;###autoload
  (defun w3m-lnum-follow (arg)
***************
*** 694,701 ****
  If image - toggle it.
  With prefix ARG visit link in new session or don't move over
  field/button/image on activation/push/toggle.
! With `-' ARG, for link image - go to it and toggle it.
! With -4 ARG, for link image - toggle it.
  With double prefix ARG, prompt for url to visit.
  With triple prefix ARG, prompt for url to visit in new session."
    (interactive "p")
--- 757,764 ----
  If image - toggle it.
  With prefix ARG visit link in new session or don't move over
  field/button/image on activation/push/toggle.
! With `-' ARG, for link image - go to it and toggle it, if link,
! visit in background.  With -4 ARG, for link image - toggle it.
  With double prefix ARG, prompt for url to visit.
  With triple prefix ARG, prompt for url to visit in new session."
    (interactive "p")
***************
*** 713,732 ****
  		((stringp action)	; url
  		 (cond ((or (= arg 1) (and (= arg -1) ; visit
  					   (not (nth 2 info))))
! 			(w3m-lnum-visit info))
  		       ((= arg -1)	; goto image and toggle it
  			(goto-char (cadr info))
  			(w3m-toggle-inline-image))
! 		       ((or (= arg 4) (and (= arg -4) ; new session
! 					   (not (nth 2 info))))
  			(w3m-lnum-visit info t))
! 		       ((= arg -4) (save-excursion ; toggle image
! 				     (goto-char (cadr info))
! 				     (w3m-toggle-inline-image)))
  		       ((= arg 16)	; prompt for url
  			(w3m-lnum-visit info nil t))
  		       ((= arg 64)    ; prompt for url for new session
! 			(w3m-lnum-visit info t t))))
  		((eq (car action) 'w3m-form-submit) ; button
  		 (when (= arg 1)
  		   (push-mark (point))
--- 776,799 ----
  		((stringp action)	; url
  		 (cond ((or (= arg 1) (and (= arg -1) ; visit
  					   (not (nth 2 info))))
! 			(w3m-lnum-visit info (if (= arg -1)
! 						 :background
! 					       t)))
  		       ((= arg -1)	; goto image and toggle it
  			(goto-char (cadr info))
  			(w3m-toggle-inline-image))
! 		       ((= arg 4)	; new session
  			(w3m-lnum-visit info t))
! 		       ((and (= arg -4) (nth 2 info))
! 			(save-excursion ; toggle image
! 			  (goto-char (cadr info))
! 			  (w3m-toggle-inline-image)))
  		       ((= arg 16)	; prompt for url
  			(w3m-lnum-visit info nil t))
  		       ((= arg 64)    ; prompt for url for new session
! 			(w3m-lnum-visit info t t))
! 		       ((= arg -4) ; prompt for url and open in background
! 			(w3m-lnum-visit info :background t))))
  		((eq (car action) 'w3m-form-submit) ; button
  		 (when (= arg 1)
  		   (push-mark (point))