2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
[bpt/emacs.git] / lisp / org / org-mouse.el
index 8d20321..c911db9 100644 (file)
@@ -1,10 +1,10 @@
 ;;; org-mouse.el --- Better mouse support for org-mode
 
-;; Copyright (C) 2006, 2007, 2008 Free Software Foundation
+;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation
 ;;
 ;; Author: Piotr Zielinski <piotr dot zielinski at gmail dot com>
 ;; Maintainer: Carsten Dominik <carsten at orgmode dot org>
-;; Version: 6.12a
+;; Version: 6.29c
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -50,7 +50,7 @@
 ;;    (require 'org-mouse)
 ;;
 
-;; Fixme:
+;; FIXME:
 ;; + deal with folding / unfolding issues
 
 ;; TODO (This list is only theoretical, if you'd like to have some
@@ -68,7 +68,7 @@
 
 ;; History:
 ;;
-;; SInce version 5.10: Changes are listed in the general org-mode docs.
+;; Since version 5.10: Changes are listed in the general org-mode docs.
 ;;
 ;; Version 5.09
 ;; + Version number synchronization with Org-mode.
 (defvar org-agenda-undo-list)
 (defvar org-agenda-custom-commands)
 (declare-function org-agenda-change-all-lines "org-agenda"
-                 (newhead hdmarker &optional fixface))
+                 (newhead hdmarker &optional fixface just-this))
 (declare-function org-verify-change-for-undo "org-agenda" (l1 l2))
 
 (defvar org-mouse-plain-list-regexp "\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) "
@@ -177,7 +177,7 @@ Changing this variable requires a restart of Emacs to get activated."
              (const :tag "S-mouse-2 and drag-mouse-3 yank link" yank-link)
              (const :tag "Activate headline stars" activate-stars)
              (const :tag "Activate item bullets" activate-bullets)
-             (const :tag "Activate checkboxes" activate-checkboxes)))        
+             (const :tag "Activate checkboxes" activate-checkboxes)))
 
 (defun org-mouse-re-search-line (regexp)
   "Search the current line for a given regular expression."
@@ -209,7 +209,7 @@ this function is called.  Otherwise, the current major mode menu is used."
           (or (not mark-active)
               (sit-for (/ double-click-time 1000.0))))
       (progn
-       (select-window (posn-window (event-start event)))
+       (select-window (posn-window (event-start event)))
        (when (not (org-mouse-mark-active))
          (goto-char (posn-point (event-start event)))
          (when (not (eolp)) (save-excursion (run-hooks 'post-command-hook)))
@@ -217,11 +217,13 @@ this function is called.  Otherwise, the current major mode menu is used."
            (sit-for 0)))
        (if (functionp org-mouse-context-menu-function)
            (funcall org-mouse-context-menu-function event)
-         (mouse-major-mode-menu event prefix)))
+         (if (fboundp 'mouse-menu-major-mode-map)
+             (popup-menu (mouse-menu-major-mode-map) event prefix)
+           (org-no-warnings ; don't warn about fallback, obsolete since 23.1
+            (mouse-major-mode-menu event prefix)))))
     (setq this-command 'mouse-save-then-kill)
     (mouse-save-then-kill event)))
 
-
 (defun org-mouse-line-position ()
   "Returns `:beginning' or `:middle' or `:end', depending on the point position.
 
@@ -331,7 +333,7 @@ Returns a menu fragment consisting of KEYWORDS.  When a keyword
 is selected, group GROUP of the current match is replaced by the
 keyword.  The method ensures that both ends of the replacement
 are separated from the rest of the text in the buffer by
-individual spaces (unless NOSURROND is non-nil).
+individual spaces (unless NOSURROUND is non-nil).
 
 The final entry of the menu is always \"None\", which removes the
 match.
@@ -420,7 +422,17 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
    (loop for priority from ?A to org-lowest-priority
         collect (char-to-string priority)))
 
+(defun org-mouse-todo-menu (state)
+  "Create the menu with TODO keywords."
+  (append
+   (let ((kwds org-todo-keywords-1))
+     (org-mouse-keyword-menu
+      kwds
+      `(lambda (kwd) (org-todo kwd))
+      (lambda (kwd) (equal state kwd))))))
+
 (defun org-mouse-tag-menu ()           ;todo
+  "Create the tags menu"
   (append
    (let ((tags (org-get-tags)))
      (org-mouse-keyword-menu
@@ -439,7 +451,6 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
      ["Set Tags ..." (org-set-tags) t])))
 
 
-
 (defun org-mouse-set-tags (tags)
   (save-excursion
     ;; remove existing tags first
@@ -584,7 +595,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
      (beginning-of-line)
      (looking-at "[ \t]*")
      (open-line 1)
-     (indent-to (- (match-end 0) (match-beginning 0)))
+     (org-indent-to-column (- (match-end 0) (match-beginning 0)))
      (insert "+ "))
 
     (:middle                   ; insert after
@@ -619,9 +630,6 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
        (set-match-data ',match)
        (apply ',function rest)))))
 
-(defun org-mouse-todo-keywords ()
-  (if (boundp 'org-todo-keywords-1) org-todo-keywords-1 org-todo-keywords))
-
 (defun org-mouse-match-todo-keyword ()
   (save-excursion
     (org-back-to-heading)
@@ -689,10 +697,10 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
                         (org-mouse-remove-match-and-spaces))))]
        )))
    ((and (org-mouse-looking-at "\\b\\w+" "a-zA-Z0-9_")
-        (member (match-string 0) (org-mouse-todo-keywords)))
+        (member (match-string 0) org-todo-keywords-1))
     (popup-menu
      `(nil
-       ,@(org-mouse-keyword-replace-menu (org-mouse-todo-keywords))
+       ,@(org-mouse-todo-menu (match-string 0))
        "--"
        ["Check TODOs" org-show-todo-tree t]
        ["List all TODO keywords" org-todo-list t]
@@ -716,7 +724,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
        ["Open" org-open-at-point t]
        ["Open in Emacs" (org-open-at-point t) t]
        "--"
-       ["Copy link" (kill-new (match-string 0))]
+       ["Copy link" (org-kill-new (match-string 0))]
        ["Cut link"
        (progn
          (kill-region (match-beginning 0) (match-end 0))
@@ -830,9 +838,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
          "--"
          ,@(org-mouse-tag-menu))
         ("TODO Status"
-         ,@(progn (org-mouse-match-todo-keyword)
-                  (org-mouse-keyword-replace-menu (org-mouse-todo-keywords)
-                                                  1)))
+         ,@(org-mouse-todo-menu (org-get-todo-state)))
         ["Show Tags"
          (with-current-buffer org-mouse-main-buffer (org-agenda-show-tags))
          :visible (not org-mouse-direct)]
@@ -874,14 +880,14 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
 ;; (defun org-mouse-at-regexp (regexp)
 ;;   (save-excursion
 ;;     (let ((point (point))
-;;       (bol (progn (beginning-of-line) (point)))
-;;       (eol (progn (end-of-line) (point))))
-;;       (goto-char point)
-;;       (re-search-backward regexp bol 1)
-;;       (and (not (eolp))
-;;        (progn (forward-char)
-;;               (re-search-forward regexp eol t))
-;;        (<= (match-beginning 0) point)))))
+;;       (bol (progn (beginning-of-line) (point)))
+;;       (eol (progn (end-of-line) (point))))
+;;      (goto-char point)
+;;      (re-search-backward regexp bol 1)
+;;      (and (not (eolp))
+;;        (progn (forward-char)
+;;               (re-search-forward regexp eol t))
+;;        (<= (match-beginning 0) point)))))
 
 (defun org-mouse-mark-active ()
   (and mark-active transient-mark-mode))
@@ -922,7 +928,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
        `((,outline-regexp
           0 `(face org-link mouse-face highlight keymap ,org-mouse-map)
           'prepend))
-       t))
+       t))
 
      (when (memq 'activate-bullets org-mouse-features)
        (font-lock-add-keywords
@@ -930,14 +936,14 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
        `(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +"
           (1 `(face org-link keymap ,org-mouse-map mouse-face highlight)
              'prepend)))
-       t))
+       t))
 
      (when (memq 'activate-checkboxes org-mouse-features)
        (font-lock-add-keywords
        nil
        `(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +\\(\\[[ X]\\]\\)"
           (2 `(face bold keymap ,org-mouse-map mouse-face highlight) t)))
-       t))
+       t))
 
      (defadvice org-open-at-point (around org-mouse-open-at-point activate)
        (let ((context (org-context)))
@@ -1130,8 +1136,8 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
        (if (featurep 'xemacs) [button3] [mouse-3])
        'org-mouse-show-context-menu)
      (define-key org-agenda-keymap [down-mouse-3] 'org-mouse-move-tree-start)
-     (define-key org-agenda-keymap [C-mouse-4] 'org-agenda-earlier)
-     (define-key org-agenda-keymap [C-mouse-5] 'org-agenda-later)
+     (define-key org-agenda-keymap (if (featurep 'xemacs) [(control mouse-4)] [C-mouse-4]) 'org-agenda-earlier)
+     (define-key org-agenda-keymap (if (featurep 'xemacs) [(control mouse-5)] [C-mouse-5]) 'org-agenda-later)
      (define-key org-agenda-keymap [drag-mouse-3]
        '(lambda (event) (interactive "e")
          (case (org-mouse-get-gesture event)