Browse Source

pcomplete: improve header arguments completion

* lisp/org-pcomplete.el (pcomplete/org-mode/block-option/src): Make it
complete all available header arguments.

* testing/lisp/test-org-pcomplete.el (test-org-pcomplete/src-block):
New test.
stardiviner 1 month ago
parent
commit
1abf4f600a
2 changed files with 26 additions and 5 deletions
  1. 11 5
      lisp/org-pcomplete.el
  2. 15 0
      testing/lisp/test-org-pcomplete.el

+ 11 - 5
lisp/org-pcomplete.el

@@ -418,11 +418,17 @@ switches."
 				    (symbol-plist
 				     'org-babel-load-languages)
 				    'custom-type)))))))
-  (while (pcomplete-here
-	  '("-n" "-r" "-l"
-	    ":cache" ":colnames" ":comments" ":dir" ":eval" ":exports"
-	    ":file" ":hlines" ":no-expand" ":noweb" ":results" ":rownames"
-	    ":session" ":shebang" ":tangle" ":tangle-mode" ":var"))))
+  (let* ((info (org-babel-get-src-block-info 'light))
+	 (lang (car info))
+	 (lang-headers (intern (concat "org-babel-header-args:" lang)))
+	 (headers (org-babel-combine-header-arg-lists
+		   org-babel-common-header-args-w-values
+		   (and (boundp lang-headers) (eval lang-headers t)))))
+    (while (pcomplete-here
+	    (append (mapcar
+		     (lambda (arg) (format ":%s" (symbol-name (car arg))))
+		     headers)
+		    '("-n" "-r" "-l"))))))
 
 (defun pcomplete/org-mode/block-option/clocktable ()
   "Complete keywords in a clocktable line."

+ 15 - 0
testing/lisp/test-org-pcomplete.el

@@ -75,6 +75,21 @@
       (buffer-string))
     t)))
 
+(ert-deftest test-org-pcomplete/src-block ()
+  "Test Babel source block header arguments completion."
+  (should
+   (string-prefix-p
+    "#+begin_src emacs-lisp"
+    (org-test-with-temp-text "#+begin_src emac<point>"
+      (pcomplete)
+      (buffer-string))))
+  (should
+   (string-prefix-p
+    "#+begin_src emacs-lisp :session"
+    (org-test-with-temp-text "#+begin_src emacs-lisp :sess<point>"
+      (pcomplete)
+      (buffer-string)))))
+
 (ert-deftest test-org-pcomplete/link ()
   "Test link completion"
   (should