Browse Source

org-pcomplete: Fix keyword and block completion

* lisp/org-pcomplete.el (pcomplete/org-mode/file-option): Apply removal
  of `org-element-block-name-alist'.
Nicolas Goaziou 9 years ago
parent
commit
ad83f31318
2 changed files with 31 additions and 14 deletions
  1. 14 12
      lisp/org-pcomplete.el
  2. 17 2
      testing/lisp/test-org-pcomplete.el

+ 14 - 12
lisp/org-pcomplete.el

@@ -1,6 +1,6 @@
 ;;; org-pcomplete.el --- In-buffer completion code
 
-;; Copyright (C) 2004-2015 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2016 Free Software Foundation, Inc.
 ;;
 ;; Author: Carsten Dominik <carsten at orgmode dot org>
 ;;         John Wiegley <johnw at gnu dot org>
@@ -142,7 +142,6 @@ When completing for #+STARTUP, for example, this function returns
 		pcomplete-default-completion-function))))
 
 (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 ()
@@ -155,16 +154,19 @@ When completing for #+STARTUP, for example, this function returns
 	    (mapcar (lambda (keyword) (concat keyword ": "))
 		    org-element-affiliated-keywords)
 	    (let (block-names)
-	      (dolist (block-info org-element-block-name-alist block-names)
-		(let ((name (car block-info)))
-		  (push (format "END_%s" name) block-names)
-		  (push (concat "BEGIN_"
-				name
-				;; Since language is compulsory in
-				;; source blocks, add a space.
-				(and (equal name "SRC") " "))
-			block-names)
-		  (push (format "ATTR_%s: " name) block-names))))
+	      (dolist (name
+		       '("CENTER" "COMMENT" "EXAMPLE" "EXPORT" "QUOTE" "SRC"
+			 "VERSE")
+		       block-names)
+		(push (format "END_%s" name) block-names)
+		(push (concat "BEGIN_"
+			      name
+			      ;; Since language is compulsory in
+			      ;; export blocks source blocks, add
+			      ;; a space.
+			      (and (member name '("EXPORT" "SRC")) " "))
+		      block-names)
+		(push (format "ATTR_%s: " name) block-names)))
 	    (mapcar (lambda (keyword) (concat keyword ": "))
 		    (org-get-export-keywords))))
    (substring pcomplete-stub 2)))

+ 17 - 2
testing/lisp/test-org-pcomplete.el

@@ -1,6 +1,6 @@
 ;;; test-org-pcomplete.el --- test pcomplete integration
 
-;; Copyright (C) 2015  Alexey Lebedeff
+;; Copyright (C) 2015-2016  Alexey Lebedeff
 ;; Authors: Alexey Lebedeff
 
 ;; This file is not part of GNU Emacs.
@@ -25,7 +25,7 @@
 ;;; Code:
 
 (ert-deftest test-org-pcomplete/prop ()
-  "Test property completion behaviour in an Org buffer"
+  "Test property completion."
   ;; Drawer where we are currently completing property name is
   ;; malformed in any case, it'll become valid only after successful
   ;; completion.  We expect that this completion process will finish
@@ -39,5 +39,20 @@
 	(pcomplete))
       (buffer-string)))))
 
+(ert-deftest test-org-pcomplete/keyword ()
+  "Test keyword and block completion."
+  (should
+   (equal
+    "#+startup: "
+    (org-test-with-temp-text "#+start<point>"
+      (pcomplete)
+      (buffer-string))))
+  (should
+   (equal
+    "#+begin_center"
+    (org-test-with-temp-text "#+begin_ce<point>"
+      (pcomplete)
+      (buffer-string)))))
+
 (provide 'test-org-pcomplete)
 ;;; test-org-pcomplete.el ends here