summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2013-01-27 23:09:31 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2013-02-06 22:06:31 (GMT)
commite14cf78056a0a4d1528b700d462b21172cd7afeb (patch)
treeee8c7737800896bbe88214c7b86c1ef536b74791
parenta2f56264c918b679b53c5b7df0ef2e01a77c63d4 (diff)
downloadorg-mode-e14cf78056a0a4d1528b700d462b21172cd7afeb.zip
org-mode-e14cf78056a0a4d1528b700d462b21172cd7afeb.tar.gz
org-pcomplete: Modify completion for buffer keywords
* lisp/org-pcomplete.el (pcomplete/org-mode/file-option): Collect valid keywords for completion without requiring the whole export framework. (pcomplete/org-mode/file-option/options): Rewrite using new export framework. Only complete up to the colon. (pcomplete/org-mode/file-option/x): Removed macro. (pcomplete/org-mode/file-option/title, pcomplete/org-mode/file-option/author, pcomplete/org-mode/file-option/email, pcomplete/org-mode/file-option/date): Removed functions. (pcomplete/org-mode/file-option/infojs_opt): New function. Completion for some keywords was removed because it provided only the default value, which is the same as not writing the keyword at all. In other words, a user would almost always want to modify the completed value, which makes the completion moot.
-rw-r--r--lisp/org-pcomplete.el71
1 files changed, 37 insertions, 34 deletions
diff --git a/lisp/org-pcomplete.el b/lisp/org-pcomplete.el
index abc7c98..3f445f1 100644
--- a/lisp/org-pcomplete.el
+++ b/lisp/org-pcomplete.el
@@ -35,7 +35,6 @@
(require 'pcomplete)
(declare-function org-split-string "org" (string &optional separators))
-(declare-function org-get-current-options "org-exp" ())
(declare-function org-make-org-heading-search-string "org"
(&optional string heading))
(declare-function org-get-buffer-tags "org" ())
@@ -140,11 +139,12 @@ When completing for #+STARTUP, for example, this function returns
(car (org-thing-at-point)))
pcomplete-default-completion-function))))
-(defvar org-options-keywords) ; From org.el
-(defvar org-additional-option-like-keywords) ; From org.el
+(defvar org-options-keywords) ; From org.el
+(defvar org-element-block-name-alist) ; From org-element.el
+(defvar org-element-affiliated-keywords) ; From org-element.el
+(declare-function org-get-export-keywords "org" ())
(defun pcomplete/org-mode/file-option ()
"Complete against all valid file options."
- (require 'org-exp)
(pcomplete-here
(org-pcomplete-case-double
(mapcar (lambda (x)
@@ -152,7 +152,16 @@ When completing for #+STARTUP, for example, this function returns
(concat x " ")
x))
(append org-options-keywords
- org-additional-option-like-keywords)))
+ org-element-affiliated-keywords
+ (let (block-names)
+ (mapc (lambda (block-name)
+ (let ((name (car block-name)))
+ (push (concat "END_" name) block-names)
+ (push (concat "BEGIN_" name) block-names)))
+ org-element-block-name-alist)
+ block-names)
+ (mapcar (lambda (keyword) (concat keyword ":"))
+ (org-get-export-keywords)))))
(substring pcomplete-stub 2)))
(defvar org-startup-options)
@@ -169,37 +178,31 @@ 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"))
+ (while (pcomplete-here
+ (pcomplete-uniqify-list
+ (append
+ ;; Hard-coded OPTION items always available.
+ '("H:" "\\n:" "num:" "timestamp:" "arch:" "author:" "c:"
+ "creator:" "date:" "d:" "email:" "*:" "e:" "::" "f:"
+ "inline:" "tex:" "p:" "pri:" "':" "-:" "stat:" "^:" "toc:"
+ "|:" "tags:" "tasks:" "<:" "todo:")
+ ;; OPTION items from registered back-ends.
+ (let (items)
+ (dolist (back-end (org-bound-and-true-p
+ org-export-registered-backends))
+ (dolist (option (plist-get (cdr back-end) :options-alist))
+ (let ((item (nth 2 option)))
+ (when item (push (concat item ":") items)))))
+ items))))))
+
+(defun pcomplete/org-mode/file-option/infojs_opt ()
+ "Complete arguments for the #+INFOJS_OPT file option."
+ (while (pcomplete-here
+ (pcomplete-uniqify-list
+ (mapcar (lambda (item) (format "%s:" (car item)))
+ (org-bound-and-true-p org-infojs-opts-table))))))
(defun pcomplete/org-mode/file-option/bind ()
"Complete arguments for the #+BIND file option, which are variable names."