summaryrefslogtreecommitdiff
path: root/lisp/org/org-pcomplete.el
diff options
context:
space:
mode:
authorBastien Guerry <bzg@gnu.org>2012-09-30 17:14:59 +0200
committerBastien Guerry <bzg@gnu.org>2012-09-30 17:14:59 +0200
commit8223b1d23361b74ede10bac47974ce7803804380 (patch)
tree3a2491c5193fed1bef14acd45092c0b9736fa5d6 /lisp/org/org-pcomplete.el
parent163227893c97b5b41039ea9d5ceadb7e5b2d570c (diff)
downloademacs-8223b1d23361b74ede10bac47974ce7803804380.tar.gz
Sync Org 7.9.2 from the commit tagged "release_7.9.2" in Org's Git repo.
Diffstat (limited to 'lisp/org/org-pcomplete.el')
-rw-r--r--lisp/org/org-pcomplete.el109
1 files changed, 84 insertions, 25 deletions
diff --git a/lisp/org/org-pcomplete.el b/lisp/org/org-pcomplete.el
index 5950d8e26da..64678409920 100644
--- a/lisp/org/org-pcomplete.el
+++ b/lisp/org/org-pcomplete.el
@@ -31,6 +31,7 @@
(require 'cl))
(require 'org-macs)
+(require 'org-compat)
(require 'pcomplete)
(declare-function org-split-string "org" (string &optional separators))
@@ -50,14 +51,17 @@
:tag "Org"
:group 'org)
+(defvar org-drawer-regexp)
+(defvar org-property-re)
+
(defun org-thing-at-point ()
"Examine the thing at point and let the caller know what it is.
The return value is a string naming the thing at point."
(let ((beg1 (save-excursion
- (skip-chars-backward (org-re "[:alnum:]_@"))
+ (skip-chars-backward (org-re "[:alnum:]-_@"))
(point)))
(beg (save-excursion
- (skip-chars-backward "a-zA-Z0-9_:$")
+ (skip-chars-backward "a-zA-Z0-9-_:$")
(point)))
(line-to-here (buffer-substring (point-at-bol) (point))))
(cond
@@ -84,8 +88,18 @@ The return value is a string naming the thing at point."
(equal (char-after (point-at-bol)) ?*))
(cons "tag" nil))
((and (equal (char-before beg1) ?:)
- (not (equal (char-after (point-at-bol)) ?*)))
+ (not (equal (char-after (point-at-bol)) ?*))
+ (save-excursion
+ (move-beginning-of-line 1)
+ (skip-chars-backward "[ \t\n]")
+ ;; org-drawer-regexp matches a whole line but while
+ ;; looking-back, we just ignore trailing whitespaces
+ (or (org-looking-back (substring org-drawer-regexp 0 -1))
+ (org-looking-back org-property-re))))
(cons "prop" nil))
+ ((and (equal (char-before beg1) ?:)
+ (not (equal (char-after (point-at-bol)) ?*)))
+ (cons "drawer" nil))
(t nil))))
(defun org-command-at-point ()
@@ -119,7 +133,6 @@ When completing for #+STARTUP, for example, this function returns
args)))
(cons (reverse args) (reverse begins))))))
-
(defun org-pcomplete-initial ()
"Calls the right completion function for first argument completions."
(ignore
@@ -127,7 +140,8 @@ When completing for #+STARTUP, for example, this function returns
(car (org-thing-at-point)))
pcomplete-default-completion-function))))
-(defvar org-additional-option-like-keywords)
+(defvar org-options-keywords) ; From org.el
+(defvar org-additional-option-like-keywords) ; From org.el
(defun pcomplete/org-mode/file-option ()
"Complete against all valid file options."
(require 'org-exp)
@@ -137,14 +151,8 @@ When completing for #+STARTUP, for example, this function returns
(if (= ?: (aref x (1- (length x))))
(concat x " ")
x))
- (delq nil
- (pcomplete-uniqify-list
- (append
- (mapcar (lambda (x)
- (if (string-match "^#\\+\\([A-Z_]+:?\\)" x)
- (match-string 1 x)))
- (org-split-string (org-get-current-options) "\n"))
- (copy-sequence org-additional-option-like-keywords))))))
+ (append org-options-keywords
+ org-additional-option-like-keywords)))
(substring pcomplete-stub 2)))
(defvar org-startup-options)
@@ -161,8 +169,40 @@ When completing for #+STARTUP, for example, this function returns
(setq opts (delete "showstars" opts)))))
opts))))
+(defmacro pcomplete/org-mode/file-option/x (option)
+ "Complete arguments for OPTION."
+ `(while
+ (pcomplete-here
+ (pcomplete-uniqify-list
+ (delq nil
+ (mapcar (lambda(o)
+ (when (string-match (concat "^[ \t]*#\\+"
+ ,option ":[ \t]+\\(.*\\)[ \t]*$") o)
+ (match-string 1 o)))
+ (split-string (org-get-current-options) "\n")))))))
+
+(defun pcomplete/org-mode/file-option/options ()
+ "Complete arguments for the #+OPTIONS file option."
+ (pcomplete/org-mode/file-option/x "OPTIONS"))
+
+(defun pcomplete/org-mode/file-option/title ()
+ "Complete arguments for the #+TITLE file option."
+ (pcomplete/org-mode/file-option/x "TITLE"))
+
+(defun pcomplete/org-mode/file-option/author ()
+ "Complete arguments for the #+AUTHOR file option."
+ (pcomplete/org-mode/file-option/x "AUTHOR"))
+
+(defun pcomplete/org-mode/file-option/email ()
+ "Complete arguments for the #+EMAIL file option."
+ (pcomplete/org-mode/file-option/x "EMAIL"))
+
+(defun pcomplete/org-mode/file-option/date ()
+ "Complete arguments for the #+DATE file option."
+ (pcomplete/org-mode/file-option/x "DATE"))
+
(defun pcomplete/org-mode/file-option/bind ()
- "Complete arguments for the #+BIND file option, which are variable names"
+ "Complete arguments for the #+BIND file option, which are variable names."
(let (vars)
(mapatoms
(lambda (a) (if (boundp a) (setq vars (cons (symbol-name a) vars)))))
@@ -196,16 +236,16 @@ When completing for #+STARTUP, for example, this function returns
"Complete against all headings.
This needs more work, to handle headings with lots of spaces in them."
(while
- (pcomplete-here
- (save-excursion
- (goto-char (point-min))
- (let (tbl)
- (while (re-search-forward org-todo-line-regexp nil t)
- (push (org-make-org-heading-search-string
- (match-string-no-properties 3) t)
- tbl))
- (pcomplete-uniqify-list tbl)))
- (substring pcomplete-stub 1))))
+ (pcomplete-here
+ (save-excursion
+ (goto-char (point-min))
+ (let (tbl)
+ (while (re-search-forward org-todo-line-regexp nil t)
+ (push (org-make-org-heading-search-string
+ (match-string-no-properties 3) t)
+ tbl))
+ (pcomplete-uniqify-list tbl)))
+ (substring pcomplete-stub 1))))
(defvar org-tag-alist)
(defun pcomplete/org-mode/tag ()
@@ -239,6 +279,25 @@ This needs more work, to handle headings with lots of spaces in them."
lst))
(substring pcomplete-stub 1)))
+(defvar org-drawers)
+
+(defun pcomplete/org-mode/drawer ()
+ "Complete a drawer name."
+ (let ((spc (save-excursion
+ (move-beginning-of-line 1)
+ (looking-at "^\\([ \t]*\\):")
+ (match-string 1)))
+ (cpllist (mapcar (lambda (x) (concat x ": ")) org-drawers)))
+ (pcomplete-here cpllist
+ (substring pcomplete-stub 1)
+ (unless (or (not (delete
+ nil
+ (mapcar (lambda(x)
+ (string-match (substring pcomplete-stub 1) x))
+ cpllist)))
+ (looking-at "[ \t]*\n.*:END:"))
+ (save-excursion (insert "\n" spc ":END:"))))))
+
(defun pcomplete/org-mode/block-option/src ()
"Complete the arguments of a begin_src block.
Complete a language in the first field, the header arguments and switches."
@@ -256,7 +315,7 @@ Complete a language in the first field, the header arguments and switches."
":session" ":shebang" ":tangle" ":var"))))
(defun pcomplete/org-mode/block-option/clocktable ()
- "Complete keywords in a clocktable line"
+ "Complete keywords in a clocktable line."
(while (pcomplete-here '(":maxlevel" ":scope"
":tstart" ":tend" ":block" ":step"
":stepskip0" ":fileskip0"