From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: (Maybe) refactor `org-babel-insert-header-arg'? Date: Tue, 05 Aug 2014 18:22:22 +0200 Message-ID: <87ppgevrcx.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEhY1-00070l-Pb for emacs-orgmode@gnu.org; Tue, 05 Aug 2014 12:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEhXu-0006cV-8q for emacs-orgmode@gnu.org; Tue, 05 Aug 2014 12:25:13 -0400 Received: from plane.gmane.org ([80.91.229.3]:49330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEhXu-0006aO-3O for emacs-orgmode@gnu.org; Tue, 05 Aug 2014 12:25:06 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XEhXs-0002Bz-SV for emacs-orgmode@gnu.org; Tue, 05 Aug 2014 18:25:04 +0200 Received: from e178062049.adsl.alicedsl.de ([85.178.62.49]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 05 Aug 2014 18:25:04 +0200 Received: from tjolitz by e178062049.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 05 Aug 2014 18:25:04 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi, maybe make parts of `org-babel-insert-header-arg' reusable by a refactoring like this? ;; refactored org-babel-insert-header-arg (part 1) #+begin_src emacs-lisp (defun tj/prompt-for-header-arg (&optional lang) "Prompt for header argument selecting from lists of common args and values. Optional argument LANG specifies the Org Babel language." (interactive) (let* ((curr-block (ignore-errors (org-babel-goto-src-block-head) (org-element-src-block-parser (point-max) nil))) (lang (or lang (condition-case err (org-element-property :language curr-block) (error "Cannot determine language")))) (lang-headers (intern (concat "org-babel-header-args:" lang))) (headers (org-babel-combine-header-arg-lists org-babel-common-header-args-w-values (when (boundp lang-headers) (eval lang-headers)))) (header-arg (org-icompleting-read "Header Arg: " (mapcar (lambda (header-spec) (symbol-name (car header-spec))) headers))) (vals (cdr (assoc (intern header-arg) headers))) (value (cond ((eq vals :any) (read-from-minibuffer "value: ")) ((listp vals) (mapconcat (lambda (group) (let ((arg (org-icompleting-read "Value: " (cons "default" (mapcar #'symbol-name group))))) (if (and arg (not (string= "default" arg))) (concat arg " ") ""))) vals ""))))) (cons header-arg value))) #+end_src ;; refactored org-babel-insert-header-arg (part 2) #+begin_src emacs-lisp (defun tj/insert-header-arg (header-arg &optional value keyword-p) "Insert HEADER-ARG with (optional) VALUE on header line. If optional arg KEYWORD-P is non-nil, insert as separate '#+header:' line on top of src-block." (when (ignore-errors (org-babel-goto-src-block-head)) (if keyword-p (progn (newline) (forward-line -1) (insert (format "#+header: :%s%s" header-arg (if value (concat " " value) "")))) (save-excursion (goto-char (point-at-eol)) (unless (= (char-before (point)) ?\ ) (insert " ")) (insert ":" header-arg) (when value (insert " " value)))))) #+end_src -- cheers, Thorsten