diff options
author | Johan Claesson <[email protected]> | 2016-07-15 17:12:09 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2016-08-31 16:40:25 +0200 |
commit | b5a4c4a31e06db72b84df2c40163c2944388863a (patch) | |
tree | 58918a9758e9ca9f59a8c26f1a6829f4e7b923a5 /lib/tools/emacs | |
parent | 243a05c2474928786cf47ad06966cbf121ce8ea8 (diff) | |
download | otp-b5a4c4a31e06db72b84df2c40163c2944388863a.tar.gz otp-b5a4c4a31e06db72b84df2c40163c2944388863a.tar.bz2 otp-b5a4c4a31e06db72b84df2c40163c2944388863a.zip |
Emacs: extend support for compile options
The syntax was limited to atoms, strings and 2-tuples. This covers most
compile options but not for example {d,Macro,Value}.
Add support for N-tuples and lists.
Add a related unit test case.
Diffstat (limited to 'lib/tools/emacs')
-rw-r--r-- | lib/tools/emacs/erlang-test.el | 34 | ||||
-rw-r--r-- | lib/tools/emacs/erlang.el | 45 |
2 files changed, 55 insertions, 24 deletions
diff --git a/lib/tools/emacs/erlang-test.el b/lib/tools/emacs/erlang-test.el index 549fae4799..adf865128f 100644 --- a/lib/tools/emacs/erlang-test.el +++ b/lib/tools/emacs/erlang-test.el @@ -132,6 +132,40 @@ concatenated to form an erlang file to test on.") (should (looking-back "erlang_test:")))) +(ert-deftest erlang-test-compile-options () + (erlang-test-format-opt t + "t") + (erlang-test-format-opt nil + "nil") + (erlang-test-format-opt (cons 1 2) + "{1, 2}") + (erlang-test-format-opt (list 1) + "[1]") + (erlang-test-format-opt (list 1 2) + "[1, 2]") + (erlang-test-format-opt (list 1 2 3) + "[1, 2, 3]") + (erlang-test-format-opt 'symbol + "symbol") + (erlang-test-format-opt "string" + "\"string\"") + (erlang-test-format-opt [] + "{}") + (erlang-test-format-opt [1] + "{1}") + (erlang-test-format-opt [1 2] + "{1, 2}") + (erlang-test-format-opt [1 2 (3 [4 5 6] 7)] + "{1, 2, [3, {4, 5, 6}, 7]}")) + +(defun erlang-test-format-opt (elisp &optional expected-erlang) + (let ((erlang (inferior-erlang-format-opt elisp))) + (message "%s -> %s" elisp erlang) + (when expected-erlang + (should (equal erlang expected-erlang))) + erlang)) + + (provide 'erlang-test) ;;; erlang-test.el ends here diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el index c5904ff686..73c6b8d768 100644 --- a/lib/tools/emacs/erlang.el +++ b/lib/tools/emacs/erlang.el @@ -4358,8 +4358,7 @@ works under XEmacs.)" (require 'etags) (set (make-local-variable 'find-tag-default-function) 'erlang-find-tag-for-completion) - (if (boundp 'xref-backend-functions) - ;; Emacs 25+ + (if (>= emacs-major-version 25) (add-hook 'xref-backend-functions #'erlang-etags--xref-backend nil t) ;; Test on a function available in the Emacs 19 version @@ -5715,31 +5714,29 @@ unless the optional NO-DISPLAY is non-nil." (defun inferior-erlang-format-comma-opts (opts) (if (null opts) "" - (concat ", " (inferior-erlang-format-opts opts)))) - -(defun inferior-erlang-format-opts (opts) - (concat "[" (inferior-erlang-string-join (mapcar 'inferior-erlang-format-opt - opts) - ", ") - "]")) + (concat ", " (inferior-erlang-format-opt opts)))) (defun inferior-erlang-format-opt (opt) (cond ((stringp opt) (concat "\"" opt "\"")) - ((atom opt) (format "%s" opt)) - ((consp opt) (concat "{" (inferior-erlang-string-join - (mapcar 'inferior-erlang-format-opt - (list (car opt) (cdr opt))) - ", ") - "}")) - (t (error (format "Unexpected opt %s" opt))))) - -(defun inferior-erlang-string-join (strs sep) - (let ((result (or (car strs) ""))) - (setq strs (cdr strs)) - (while strs - (setq result (concat result sep (car strs))) - (setq strs (cdr strs))) - result)) + ((vectorp opt) (inferior-erlang-tuple (append opt nil))) + ((atom opt) (format "%s" opt)) + ((consp opt) (if (listp (cdr opt)) + (inferior-erlang-list opt) + (inferior-erlang-tuple (list (car opt) (cdr opt))))) + (t (error "Unexpected erlang compile option %s" opt)))) + +(defun inferior-erlang-tuple (opts) + (concat "{" (mapconcat 'inferior-erlang-format-opt + opts + ", ") + "}")) + +(defun inferior-erlang-list (opts) + (concat "[" (mapconcat 'inferior-erlang-format-opt + opts + ", ") + "]")) + (defun erlang-local-buffer-file-name () ;; When editing a file remotely via tramp, |