view lisp/org/org-wl.el @ 111413:d53ee71e7e89

Unify mouse-highlight code for all GUI and TTY sessions. term.c: Remove static mouse_face_* variables. All users changed. (term_show_mouse_face, term_clear_mouse_face) (fast_find_position, term_mouse_highlight): Functions deleted. (tty_draw_row_with_mouse_face): New function. (term_mouse_movement): Call note_mouse_highlight instead of term_mouse_highlight. nsterm.m (ns_update_window_begin, ns_update_window_end) (ns_update_end, x_destroy_window, ns_frame_up_to_date) (ns_dumpglyphs_box_or_relief, ns_maybe_dumpglyphs_background) (ns_dumpglyphs_image, ns_dumpglyphs_stretch) (ns_initialize_display_info, keyDown, mouseMoved, mouseExited): Replace Display_Info with Mouse_HLInfo everywhere where mouse_face_* members were accessed for mouse highlight purposes. xterm.c (x_update_window_begin, x_update_window_end) (x_update_end, XTframe_up_to_date, x_set_mouse_face_gc) (handle_one_xevent, x_free_frame_resources, x_term_init): Replace Display_Info with Mouse_HLInfo everywhere where mouse_face_* members were accessed for mouse highlight purposes. w32term.c (x_update_window_begin, x_update_window_end) (x_update_end, w32_read_socket, x_free_frame_resources) (w32_initialize_display_info): Replace Display_Info with Mouse_HLInfo everywhere where mouse_face_* members were accessed for mouse highlight purposes. xdisp.c (show_mouse_face, note_mode_line_or_margin_highlight) (note_mouse_highlight) [HAVE_WINDOW_SYSTEM]: Don't run GUI code unless the frame is on a window-system. (get_tool_bar_item, handle_tool_bar_click) (note_tool_bar_highlight, draw_glyphs, erase_phys_cursor) (show_mouse_face, clear_mouse_face, coords_in_mouse_face_p) (note_mode_line_or_margin_highlight, note_mouse_highlight) (x_clear_window_mouse_face, cancel_mouse_face, expose_frame): Replace Display_Info with Mouse_HLInfo everywhere where mouse_face_* members were accessed for mouse highlight purposes. (coords_in_mouse_face_p): Move prototype out of the HAVE_WINDOW_SYSTEM conditional. (x_y_to_hpos_vpos, frame_to_window_pixel_xy): Move out of the HAVE_WINDOW_SYSTEM block. (try_window_id) [HAVE_GPM || MSDOS]: Call x_clear_window_mouse_face. (draw_row_with_mouse_face): Implementation for HAVE_WINDOW_SYSTEM systems. Call tty_draw_row_with_mouse_face for TTY systems. (show_mouse_face): Call draw_row_with_mouse_face, instead of calling draw_glyphs directly. (show_mouse_face, clear_mouse_face, coords_in_mouse_face_p) (cursor_in_mouse_face_p, rows_from_pos_range) (mouse_face_from_buffer_pos, mouse_face_from_string_pos) (note_mode_line_or_margin_highlight, note_mouse_highlight) (x_clear_window_mouse_face, cancel_mouse_face): Move out of the HAVE_WINDOW_SYSTEM block. Ifdef away window-system specific fragments. (note_mouse_highlight): Call popup_activated for MSDOS as well. Clear mouse highlight if pointer is over glyphs whose OBJECT is an integer. (mouse_face_from_buffer_pos): Add parentheses around && within ||. (x_consider_frame_title, tool_bar_lines_needed): Move prototypes to HAVE_WINDOW_SYSTEM-only part. (get_window_cursor_type): Move inside a HAVE_WINDOW_SYSTEM-only part. Remove "#ifdef HAVE_WINDOW_SYSTEM" from body of function. (null_glyph_slice): Move declaration into HAVE_WINDOW_SYSTEM-only part. dispnew.c (mirror_make_current): Set Y coordinate of the mode-line and header-line rows. (init_display): Setup initial frame's output_data for text terminal frames. xmenu.c (popup_activated): Don't define on MSDOS, which now has its own definition on msdos.c. msdos.c (show_mouse_face, clear_mouse_face) (fast_find_position, IT_note_mode_line_highlight) (IT_note_mouse_highlight): Functions deleted. (IT_frame_up_to_date, dos_rawgetc): Call note_mouse_highlight instead of IT_note_mouse_highlight. (draw_row_with_mouse_face, popup_activated): New functions. (dos_set_window_size, draw_row_with_mouse_face, IT_update_begin) (IT_update_end, IT_frame_up_to_date, internal_terminal_init) (dos_rawgetc): Replace Display_Info with Mouse_HLInfo everywhere where mouse_face_* members were accessed for mouse highlight purposes. msdos.h (initialize_msdos_display): Add prototype. frame.h (MOUSE_HL_INFO): New macro. lisp.h (Mouse_HLInfo): New data type. xterm.h (struct x_display_info): w32term.h (struct w32_display_info): nsterm.h (struct ns_display_info): termchar.h (struct tty_display_info): Use it instead of mouse_face_* members. dispextern.h (show_mouse_face, clear_mouse_face): Update type of 1st argument. (frame_to_window_pixel_xy, note_mouse_highlight) (x_clear_window_mouse_face, cancel_mouse_face, clear_mouse_face) (show_mouse_face, cursor_in_mouse_face_p): Move prototypes out of HAVE_WINDOW_SYSTEM conditional. (draw_row_with_mouse_face): Declare prototype. (tty_draw_row_with_mouse_face): Declare prototype.
author Eli Zaretskii <eliz@gnu.org>
date Sat, 06 Nov 2010 10:28:31 +0200
parents a150e8a14679
children 5cb272c831e8
line wrap: on
line source

;;; org-wl.el --- Support for links to Wanderlust messages from within Org-mode

;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
;;   Free Software Foundation, Inc.

;; Author: Tokuya Kameshima <kames at fa2 dot so-net dot ne dot jp>
;;         David Maus <dmaus at ictsoc dot de>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 7.01
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:

;; This file implements links to Wanderlust messages from within Org-mode.
;; Org-mode loads this module by default - if this is not what you want,
;; configure the variable `org-modules'.

;;; Code:

(require 'org)

(defgroup org-wl nil
 "Options concerning the Wanderlust link."
 :tag "Org Startup"
 :group 'org-link)

(defcustom org-wl-link-to-refile-destination t
  "Create a link to the refile destination if the message is marked as refile."
  :group 'org-wl
  :type 'boolean)

(defcustom org-wl-link-remove-filter nil
  "Remove filter condition if message is filter folder."
  :group 'org-wl
  :type 'boolean)

(defcustom org-wl-shimbun-prefer-web-links nil
  "If non-nil create web links for shimbun messages."
  :group 'org-wl
  :type 'boolean)

(defcustom org-wl-nntp-prefer-web-links nil
  "If non-nil create web links for nntp messages.
When folder name contains string \"gmane\" link to gmane,
googlegroups otherwise."
  :type 'boolean
  :group 'org-wl)

(defcustom org-wl-disable-folder-check t
  "Disable check for new messages when open a link."
  :type 'boolean
  :group 'org-wl)

(defcustom org-wl-namazu-default-index nil
  "Default namazu search index."
  :type 'directory
  :group 'org-wl)

;; Declare external functions and variables
(declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
(declare-function elmo-message-entity-field "ext:elmo-msgdb"
		  (entity field &optional type))
(declare-function elmo-message-field "ext:elmo"
		  (folder number field &optional type) t)
(declare-function elmo-msgdb-overview-get-entity "ext:elmo" (id msgdb) t)
;; Backward compatibility to old version of wl
(declare-function wl "ext:wl" () t)
(declare-function wl-summary-buffer-msgdb "ext:wl-folder" () t)
(declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
		  (&optional id))
(declare-function wl-summary-line-from "ext:wl-summary" ())
(declare-function wl-summary-line-subject "ext:wl-summary" ())
(declare-function wl-summary-message-number "ext:wl-summary" ())
(declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
(declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
(declare-function wl-folder-goto-folder-subr "ext:wl-folder"
		  (&optional folder sticky))
(declare-function wl-folder-get-petname "ext:wl-folder" (name))
(declare-function wl-folder-get-entity-from-buffer "ext:wl-folder"
		  (&optional getid))
(declare-function wl-folder-buffer-group-p "ext:wl-folder")
(defvar wl-init)
(defvar wl-summary-buffer-elmo-folder)
(defvar wl-summary-buffer-folder-name)
(defvar wl-folder-group-regexp)
(defvar wl-auto-check-folder-name)

(defconst org-wl-folder-types
  '(("%" . imap) ("-" . nntp) ("+" . mh) ("=" . spool)
    ("$" . archive) ("&" . pop) ("@" . shimbun) ("[" . search)
    ("*" . multi) ("/" . filter) ("|" . pipe) ("'" . internal))
  "List of folder indicators.  See Wanderlust manual, section 3.")

;; Install the link type
(org-add-link-type "wl" 'org-wl-open)
(add-hook 'org-store-link-functions 'org-wl-store-link)

;; Implementation

(defun org-wl-folder-type (folder)
  "Return symbol that indicates the type of FOLDER.
FOLDER is the wanderlust folder name.  The first character of the
folder name determines the the folder type."
  (let* ((indicator (substring folder 0 1))
	 (type (cdr (assoc indicator org-wl-folder-types))))
    ;; maybe access or file folder
    (when (not type)
      (setq type
	    (cond
	     ((and (>= (length folder) 5)
		   (string= (substring folder 0 5) "file:"))
	      'file)
	     ((and (>= (length folder) 7)
		   (string= (substring folder 0 7) "access:"))
	      'access)
	     (t
	      nil))))
    type))

(defun org-wl-message-field (field entity)
  "Return content of FIELD in ENTITY.
FIELD is a symbol of a rfc822 message header field.
ENTITY is a message entity."
  (let ((content (elmo-message-entity-field entity field)))
    (if (listp content) (car content) content)))

(defun org-wl-store-link ()
  "Store a link to a WL message or folder."
  (cond
   ((memq major-mode '(wl-summary-mode mime-view-mode))
    (org-wl-store-link-message))
   ((eq major-mode 'wl-folder-mode)
    (org-wl-store-link-folder))
   (t
    nil)))

(defun org-wl-store-link-folder ()
  "Store a link to a WL folder."
  (let* ((folder (wl-folder-get-entity-from-buffer))
	 (petname (wl-folder-get-petname folder))
	 (link (org-make-link "wl:" folder)))
    (save-excursion
      (beginning-of-line)
      (unless (and (wl-folder-buffer-group-p)
		   (looking-at wl-folder-group-regexp))
	(org-store-link-props :type "wl" :description petname
			      :link link)
	link))))

(defun org-wl-store-link-message ()
  "Store a link to a WL message."
  (save-excursion
    (let ((buf (if (eq major-mode 'wl-summary-mode)
		   (current-buffer)
		 (and (boundp 'wl-message-buffer-cur-summary-buffer)
		      wl-message-buffer-cur-summary-buffer))))
      (when buf
	(with-current-buffer buf
	  (let* ((msgnum (wl-summary-message-number))
		 (mark-info (wl-summary-registered-temp-mark msgnum))
		 (folder-name
		  (if (and org-wl-link-to-refile-destination
			   mark-info
			   (equal (nth 1 mark-info) "o")) ; marked as refile
		      (nth 2 mark-info)
		    wl-summary-buffer-folder-name))
		 (folder-type (org-wl-folder-type folder-name))
		 (wl-message-entity
		  (if (fboundp 'elmo-message-entity)
		      (elmo-message-entity
		       wl-summary-buffer-elmo-folder msgnum)
		    (elmo-msgdb-overview-get-entity
		     msgnum (wl-summary-buffer-msgdb))))
		 (message-id
		  (org-wl-message-field 'message-id wl-message-entity))
		 (from (org-wl-message-field 'from wl-message-entity))
		 (to (org-wl-message-field 'to wl-message-entity))
		 (xref (org-wl-message-field 'xref wl-message-entity))
		 (subject (org-wl-message-field 'subject wl-message-entity))
		 desc link)

	    ;; remove text properties of subject string to avoid possible bug
	    ;; when formatting the subject
	    ;; (Emacs bug #5306, fixed)
	    (set-text-properties 0 (length subject) nil subject)

	    ;; maybe remove filter condition
	    (when (and (eq folder-type 'filter) org-wl-link-remove-filter)
	      (while (eq (org-wl-folder-type folder-name) 'filter)
		(setq folder-name
		      (replace-regexp-in-string "^/[^/]+/" "" folder-name))))

	    ;; maybe create http link
	    (cond
	     ((and (eq folder-type 'shimbun)
		   org-wl-shimbun-prefer-web-links xref)
	      (org-store-link-props :type "http" :link xref :description subject
				    :from from :to to :message-id message-id
				    :subject subject))
	     ((and (eq folder-type 'nntp) org-wl-nntp-prefer-web-links)
	      (setq link
		    (format
		     (if (string-match "gmane\\." folder-name)
			 "http://mid.gmane.org/%s"
		       "http://groups.google.com/groups/search?as_umsgid=%s")
		     (org-fixup-message-id-for-http message-id)))
	      (org-store-link-props :type "http" :link link :description subject
				    :from from :to to :message-id message-id
				    :subject subject))
	     (t
	      (org-store-link-props :type "wl" :from from :to to
				    :subject subject :message-id message-id)
	      (setq message-id (org-remove-angle-brackets message-id))
	      (setq desc (org-email-link-description))
	      (setq link (org-make-link "wl:" folder-name "#" message-id))
	      (org-add-link-props :link link :description desc)))
	    (or link xref)))))))

(defun org-wl-open (path)
  "Follow the WL message link specified by PATH.
When called with one prefix, open message in namazu search folder
with `org-wl-namazu-default-index' as search index.  When called
with two prefixes or `org-wl-namazu-default-index' is nil, ask
for namazu index."
  (require 'wl)
  (let ((wl-auto-check-folder-name
	 (if org-wl-disable-folder-check
	     'none
	   wl-auto-check-folder-name)))
    (unless wl-init (wl))
    ;; XXX: The imap-uw's MH folder names start with "%#".
    (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
	(error "Error in Wanderlust link"))
    (let ((folder (match-string 1 path))
	  (article (match-string 3 path)))
      ;; maybe open message in namazu search folder
      (when current-prefix-arg
	(setq folder (concat "[" article "]"
			     (if (and (equal current-prefix-arg '(4))
				      org-wl-namazu-default-index)
				 org-wl-namazu-default-index
			       (read-directory-name "Namazu index: ")))))
      (if (not (elmo-folder-exists-p (org-no-warnings
				      (wl-folder-get-elmo-folder folder))))
	  (error "No such folder: %s" folder))
      (let ((old-buf (current-buffer))
	    (old-point (point-marker)))
	(wl-folder-goto-folder-subr folder)
	(with-current-buffer old-buf
	  ;; XXX: `wl-folder-goto-folder-subr' moves point to the
	  ;; beginning of the current line.  So, restore the point
	  ;; in the old buffer.
	  (goto-char old-point))
	(and article (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
							    article))
	     (wl-summary-redisplay))))))

(provide 'org-wl)

;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a

;;; org-wl.el ends here