[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: right clicking on URL in emacs-w3m vs. gnus
- From: Katsumi Yamaoka <yamaoka@xxxxxxx>
- Date: Wed, 21 Apr 2010 15:08:26 +0900
- X-ml-name: emacs-w3m
- X-mail-count: 11213
- References: <87sk6thfcc.fsf@xxxxxxxxxxx> <87sk6qf3bu.fsf@xxxxxxxxxxxx>
>>>>> Ted Zlatanov wrote:
(B> On Sun, 18 Apr 2010 06:41:23 +0800 jidanni@xxxxxxxxxxx wrote:
(Bj> In emacs-w3m, right clicking on a link brings up a menu with lots of choices.
(Bj> However doing the same action inside gnus doesn't.
(Bj> E.g., try right clicking on http://example.org/ .
(B> This is composed of two things actually:
(B> 1) the emacs-w3m popup menu should be accessible in the Article buffer.
(B> Currently it can be invoked with (w3m-mouse-major-mode-menu EVENT) so it
(B> *can* be bound to right-click in the article mode by the user. This
(B> part is pretty easy.
(B> 2) right-click on a URL should bring up that menu. I'm not sure if
(B> there are any other logical things to hang on right-click in Gnus. For
(B> instance we could bring up the Treatment or Commands menus that are
(B> otherwise in the pulldown. So maybe the emacs-w3m menu should be under
(B> the main popup menu in the article buffer, and it should also show up in
(B> the menu bar when the article buffer is using emacs-w3m.
(B> Any opinions?
(BI don't know what items the menu should provide but I tried hacking
(Bit as attached below. Currently the right-click pops up this menu:
(B| Open this link with
(B(The first item overlaps to the middle-click though.)
(B2010-04-21 Katsumi Yamaoka <yamaoka@xxxxxxx>
(B * gnus-art.el (gnus-article-add-buttons): Add url string as text
(B property to button.
(B (gnus-article-extend-url-button): Use text property instead of overlay
(B to add url to button.
(B (gnus-article-link-map): New variable.
(B (gnus-article-open-link-with-emacs-w3m): New functions.
(B (gnus-article-link-menu): New menu.
(B (gnus-article-add-button): Add url string as text property to button.
(B (gnus-button-push): Assume gnus-button-url is text property.
--- gnus-art.el~ 2010-04-18 23:04:00 +0000
(B+++ gnus-art.el 2010-04-21 06:07:17 +0000
(B@@ -7781,15 +7781,17 @@
(B (push from gnus-button-marker-list)
(B (unless (and (eq (car entry) 'gnus-button-url-regexp)
(B (gnus-article-extend-url-button from start end))
(B- (gnus-article-add-button start end
(B- 'gnus-button-push from)))))))))
(B+ start end 'gnus-button-push from
(B+ (and (eq (car entry) 'gnus-button-url-regexp)
(B+ (buffer-substring start end)))))))))))
(B (defun gnus-article-extend-url-button (beg start end)
(B "Extend url button if url is folded into two or more lines.
(B Return non-nil if button is extended. BEG is a marker that points to
(B the beginning position of a text containing url. START and END are
(B the endpoints of a url button before it is extended. The concatenated
(B-url is put as the `gnus-button-url' overlay property on the button."
(B+url is put as the `gnus-button-url' text property on the button."
(B (let ((opoint (point))
(B (points (list start end))
(B url delim regexp)
(B@@ -7829,14 +7831,13 @@
(B (match-beginning 1))
(B (match-beginning 2)))
(B+ (setq url (mapconcat 'identity (nreverse url) ""))
(B (let (gnus-article-mouse-face widget-mouse-face)
(B (while points
(B (gnus-article-add-button (pop points) (pop points)
(B- 'gnus-button-push beg)))
(B+ 'gnus-button-push beg url)))
(B (let ((overlay (gnus-make-overlay start end)))
(B (gnus-overlay-put overlay 'evaporate t)
(B- (gnus-overlay-put overlay 'gnus-button-url
(B- (list (mapconcat 'identity (nreverse url) "")))
(B (when gnus-article-mouse-face
(B (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
(B@@ -7874,8 +7875,45 @@
(B ;;; External functions:
(B-(defun gnus-article-add-button (from to fun &optional data)
(B- "Create a button between FROM and TO with callback FUN and data DATA."
(B+(defvar gnus-article-link-map nil)
(B+ (let ((map (make-sparse-keymap)))
(B+ (setq gnus-article-link-map map)
(B+ (cond ((featurep 'xemacs)
(B+ (define-key map [(button3)] 'gnus-article-link-menu))
(B+ ;; Don't use [mouse-3], which gets submenus not working in GTK Emacs.
(B+ ((featurep 'gtk)
(B+ (define-key map [down-mouse-3] 'gnus-article-link-menu)
(B+ (define-key map [drag-mouse-3] 'undefined)
(B+ (define-key map [mouse-3] 'undefined))
(B+ (define-key map [mouse-3] 'gnus-article-link-menu)))))
(B+(defun gnus-article-open-link-with-browse-url ()
(B+ (browse-url (get-text-property (point) 'gnus-button-url)))
(B+(defun gnus-article-open-link-with-emacs-w3m ()
(B+ (w3m (get-text-property (point) 'gnus-button-url) t t))
(B+(easy-menu-define gnus-article-link-menu gnus-article-link-map
(B+ "Link menu."
(B+ '("Open this link with"
(B+ ["browse-url" gnus-article-open-link-with-browse-url]
(B+ ["emacs-w3m" gnus-article-open-link-with-emacs-w3m]))
(B+(defun gnus-article-link-menu (event)
(B+ "Pop up a link menu."
(B+ (interactive "e")
(B+ (mouse-set-point event)
(B+ (popup-menu gnus-article-link-menu))
(B+(defun gnus-article-add-button (from to fun &optional data url)
(B+ "Create a button between FROM and TO with callback FUN and data DATA.
(B+The optional URL is a string that will be put as the `gnus-button-url'
(B+text property on the button."
(B (when gnus-article-button-face
(B (gnus-overlay-put (gnus-make-overlay from to nil t)
(B 'face gnus-article-button-face))
(B@@ -7884,7 +7922,9 @@
(B (nconc (and gnus-article-mouse-face
(B (list gnus-mouse-face-prop gnus-article-mouse-face))
(B (list 'gnus-callback fun)
(B- (and data (list 'gnus-data data))))
(B+ (and data (list 'gnus-data data))
(B+ (and url (list 'gnus-button-url url
(B+ 'keymap gnus-article-link-map))))
(B (widget-convert-button 'link from to :action 'gnus-widget-press-button
(B :button-keymap gnus-widget-button-keymap))
(B@@ -7931,13 +7971,14 @@
(B (inhibit-point-motion-hooks t)
(B (fun (nth 3 entry))
(B (args (or (and (eq (car entry) 'gnus-button-url-regexp)
(B- (get-char-property marker 'gnus-button-url))
(B+ (get-text-property marker 'gnus-button-url))
(B (mapcar (lambda (group)
(B (let ((string (match-string group)))
(B 0 (length string) nil string)
(B (nthcdr 4 entry)))))
(B+ (unless (consp args) (setq args (list args)))
(B ((fboundp fun)
(B (apply fun args))