Nicolas Goaziou <m...@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbch...@gmail.com> writes:
>
>> Add a test for Babel src block languages and header arguments.
>
> Thank you.

Glad this test is simple to write and passed.

>
>> I'm wandering how to complete header argument values? Do you have any
>> hints?
>
> You can use, again, `org-babel-common-header-args-w-values' for some
> parameters. However, most of them specify `:any', which means the value
> can be anything, and, therefore, cannot be completed.

I see. Thanks.

>
> You may want to have a look at `org-lint-wrong-header-value' for an
> example on how to treat
>
>> +(ert-deftest test-org-pcomplete/src-block ()
>> +  "Test Babel src block header arguments completion."
>
> "source block" instead of "src block".

Fixed

>
>> +  (should
>> +   (string-prefix-p
>> +    "#+begin_src emacs-lisp"
>> +    (org-test-with-temp-text "#+begin_src emac<point>"
>> +      (pcomplete)
>> +      (buffer-string))
>> +    t))
>
> You can remove the t

Done.

>
>> +  (should
>> +   (string-prefix-p
>> +    "#+begin_src emacs-lisp :session"
>> +    (org-test-with-temp-text "#+begin_src emacs-lisp :sess<point>"
>> +      (pcomplete)
>> +      (buffer-string))
>> +    t)))
>
> Ditto.

Ditto.

I attached the new patch.

>
> Regards,


-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      
From 5b0e7bb971d1459bc1247ce14bec49d897aa2fa5 Mon Sep 17 00:00:00 2001
From: stardiviner <numbch...@gmail.com>
Date: Tue, 12 May 2020 21:44:04 +0800
Subject: [PATCH] org-pcomplete.el: improve header arguments completion

* lisp/org-pcomplete.el (pcomplete/org-mode/block-option/src): Make it
complete real all available header arguments like command
`org-babel-insert-header-arg'.

* testing/lisp/test-org-pcomplete.el (test-org-pcomplete/src-block):
Test Babel source block language and header arguments completing.
---
 lisp/org-pcomplete.el              | 16 +++++++++++-----
 testing/lisp/test-org-pcomplete.el | 15 +++++++++++++++
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/lisp/org-pcomplete.el b/lisp/org-pcomplete.el
index 28b40fadd..65651512a 100644
--- a/lisp/org-pcomplete.el
+++ b/lisp/org-pcomplete.el
@@ -418,11 +418,17 @@ (defun pcomplete/org-mode/block-option/src ()
 				    (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."
diff --git a/testing/lisp/test-org-pcomplete.el b/testing/lisp/test-org-pcomplete.el
index e6b0e8a7e..2de4f4934 100644
--- a/testing/lisp/test-org-pcomplete.el
+++ b/testing/lisp/test-org-pcomplete.el
@@ -75,6 +75,21 @@ (ert-deftest test-org-pcomplete/keyword ()
       (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
-- 
2.26.2

Attachment: signature.asc
Description: PGP signature

Reply via email to