|
From: | Tobias Zawada |
Subject: | [O] Bug in org-lob: Function call adds space to argument string with parenthesis |
Date: | Fri, 18 Dec 2015 08:46:42 +0000 |
* Bug in org-lob: Function call adds space to argument string with parenthesis Dear all, Please see the following code. I would expect arg="()" as result of the call-line but the result is arg="() " with an additional space. #+NAME: test #+BEGIN_SRC emacs-lisp :var arg="" (message "arg=%S" arg) #+END_SRC #+RESULTS: : arg="" #+call: test(arg="()") #+RESULTS: : arg="() " * My current fast and dirty hack is using sexps instead of regular expressions: #+BEGIN_SRC emacs-lisp (require 'ob-lob) (defadvice org-babel-lob-get-info (around correct-args activate) "Return a Library of Babel function call as a list. 1st element is the function call as a string. 2nd element is the indentation width 3rd element is the name of the function call if this call is named." (setq ad-return-value (let ((case-fold-search t) (nonempty (lambda (a b) (let ((it (match-string a))) (if (= (length it) 0) (match-string b) it))))) (save-excursion (beginning-of-line 1) (when (looking-at org-babel-lob-one-liner-regexp) (append (list (if (= (length (match-string 12)) 0) (org-babel-lob-get-info-call-line) (org-babel-lob-get-info-inline))) (list (length (if (= (length (match-string 12)) 0) (match-string 2) (match-string 11))) (save-excursion (forward-line -1) (and (looking-at (concat org-babel-src-name-regexp "\\([^\n]*\\)$")) (org-no-properties (match-string 1))))))))))) (defun org-babel-lob-get-info-call-line () "Unify Library of Babel call string of form \"#+CALL:\" The unified syntax is ,,#+CALL: <name>[<inside header arguments>](<arguments>) <end header arguments>" (save-excursion (save-match-data (let ((name "") (inside-header-args "[]") (args "()") end-header-args) (skip-syntax-forward " ") (unless (looking-at "#\\+call:[[:space:]]+\\(\\(?:\\sw\\|\\s_\\)+\\)") (error "Expecting #+CALL: at beginning of line")) (setq name (match-string 1)) (goto-char (match-end 0)) (skip-syntax-forward " ") (when (eq (char-after) ?\[) ;; inside-header-args (setq inside-header-args (buffer-substring-no-properties (point) (goto-char (scan-sexps (point) 1))))) (skip-syntax-forward " ") (when (eq (char-after) ?\() (setq args (buffer-substring-no-properties (point) (goto-char (scan-sexps (point) 1))))) (setq end-header-args (buffer-substring-no-properties (point) (line-end-position))) (concat name inside-header-args args end-header-args))))) (defun org-babel-lob-get-info-inline () "Transform one-line Library of Babel calls of form call_<name>[<inside header arguments>](<arguments>)[<end header arguments>] into the unified syntax ,,#+CALL: <name>[<inside header arguments>](<arguments>) <end header arguments>" (save-excursion (save-match-data (let ((name "") (inside-header-args "[]") (args "()") (end-header-args "")) (skip-syntax-forward " ") (unless (looking-at "call_\\(\\(?:\\sw\\|\\s_\\)+\\)") (error "Expecting #+CALL: at beginning of line")) (setq name (match-string 1)) (goto-char (match-end 0)) (skip-syntax-forward " ") (when (eq (char-after) ?\[) ;; inside-header-args (setq inside-header-args (buffer-substring-no-properties (point) (goto-char (scan-sexps (point) 1))))) (skip-syntax-forward " ") (when (eq (char-after) ?\() (setq args (buffer-substring-no-properties (point) (goto-char (scan-sexps (point) 1))))) (when (eq (char-after) ?\[) (setq end-header-args (buffer-substring-no-properties (1+ (point)) (1- (scan-sexps (point) 1))))) (concat name inside-header-args args end-header-args))))) #+END_SRC Emacs : GNU Emacs 24.5.1 (x86_64-unknown-cygwin, GTK+ Version 3.14.13) of 2015-06-23 on desktop-new Package: Org-mode version 8.3.2 Mit freundlichen Grüßen / Best regards Tobias Zawada
itisim.com SimulationX 3.7 now available Always up to date
ITI GmbH Managing Director/Geschäftsführer Commercial Register/Handelsregister Diese E-Mail ist streng vertraulich und nur für den Empfänger bestimmt. The information in this e-mail is strictly confidential, is intended solely for the addressee, and may be privileged. |
[Prev in Thread] | Current Thread | [Next in Thread] |