Fix `sclang-make-options' falsely emitting -d and -l

It turns out `file-directory-p' and `file-exists-p' return t when passed
the empty string.  This is sort of unexpected, and leads to the logic
in `sclang-make-options' choosing to pass -d and -l with
unpredictable values (default-directory) to sclang.
A default of "" (or -1) is pretty unidiomatic for elisp, so we change
the default of user option `sclang-runtime-directory',
`sclang-library-configuration-file' and `sclang-udp-port' to
nil, and adjust `sclang-make-options' accordingly.  While we're here,
we can eliminate the use of `cl-flet'.
Additionally, `sclang-eval-sync' uses `find' which is really an
alias for `cl-find' which and can be replaced with a call to the built-in
function `assoc'.  This is faster, and the last dependency on the
cl package, which we can now remove (obsolete since emacs 27).
This commit is contained in:
Mario Lang 2019-12-24 23:18:08 +01:00
parent 6b63bf1bcf
commit 59e0d31b0a

View file

@ -16,10 +16,8 @@
;; USA ;; USA
(eval-when-compile (eval-when-compile
(require 'cl)
(require 'sclang-util) (require 'sclang-util)
(require 'compile) (require 'compile))
)
;; ===================================================================== ;; =====================================================================
;; post buffer access ;; post buffer access
@ -143,18 +141,18 @@ If EOB-P is non-nil, positions cursor at end of buffer."
:version "21.3" :version "21.3"
:type 'string) :type 'string)
(defcustom sclang-runtime-directory "" (defcustom sclang-runtime-directory nil
"*Path to the SuperCollider runtime directory." "Path to the SuperCollider runtime directory."
:group 'sclang-options :group 'sclang-options
:version "21.3" :version "21.3"
:type 'directory :type '(choice (const nil) directory)
:options '(:must-match)) :options '(:must-match))
(defcustom sclang-library-configuration-file "" (defcustom sclang-library-configuration-file nil
"*Path of the library configuration file." "Path of the library configuration file."
:group 'sclang-options :group 'sclang-options
:version "21.3" :version "21.3"
:type 'file :type '(choice (const nil) file)
:options '(:must-match)) :options '(:must-match))
(defcustom sclang-heap-size "" (defcustom sclang-heap-size ""
@ -169,11 +167,11 @@ If EOB-P is non-nil, positions cursor at end of buffer."
:version "21.3" :version "21.3"
:type 'string) :type 'string)
(defcustom sclang-udp-port -1 (defcustom sclang-udp-port nil
"*UDP listening port." "UDP listening port."
:group 'sclang-options :group 'sclang-options
:version "21.3" :version "21.3"
:type 'integer) :type '(choice (const :tag "Default" nil) integer))
(defcustom sclang-main-run nil (defcustom sclang-main-run nil
"*Call Main.run on startup." "*Call Main.run on startup."
@ -282,30 +280,28 @@ If EOB-P is non-nil, positions cursor at end of buffer."
(string-match "^[1-9][0-9]*[km]?$" string))) (string-match "^[1-9][0-9]*[km]?$" string)))
(defun sclang-port-option-p (number) (defun sclang-port-option-p (number)
(and (>= number 0) (<= number #XFFFF))) (and (integerp number) (>= number 0) (<= number #XFFFF)))
(defun sclang-make-options () (defun sclang-make-options ()
(let ((default-directory "") (let ((default-directory ""))
(res ())) (append
(cl-flet ((append-option (when (and sclang-runtime-directory
(option &optional value) (file-directory-p sclang-runtime-directory))
(setq res (append res (list option) (and value (list value)))))) (list "-d" (expand-file-name sclang-runtime-directory)))
(if (file-directory-p sclang-runtime-directory) (when (and sclang-library-configuration-file
(append-option "-d" (expand-file-name sclang-runtime-directory))) (file-exists-p sclang-library-configuration-file))
(if (file-exists-p sclang-library-configuration-file) (list "-l" (expand-file-name sclang-library-configuration-file)))
(append-option "-l" (expand-file-name sclang-library-configuration-file))) (when (sclang-memory-option-p sclang-heap-size)
(if (sclang-memory-option-p sclang-heap-size) (list "-m" sclang-heap-size))
(append-option "-m" sclang-heap-size)) (when (sclang-memory-option-p sclang-heap-growth)
(if (sclang-memory-option-p sclang-heap-growth) (list "-g" sclang-heap-growth))
(append-option "-g" sclang-heap-growth)) (when (sclang-port-option-p sclang-udp-port)
(if (sclang-port-option-p sclang-udp-port) (list "-u" (number-to-string sclang-udp-port)))
(append-option "-u" (number-to-string sclang-udp-port))) (when sclang-main-run
(if sclang-main-run (list "-r"))
(append-option "-r")) (when sclang-main-stop
(if sclang-main-stop (list "-s"))
(append-option "-s")) (list "-iscel"))))
(append-option "-iscel")
res)))
(defun sclang-start () (defun sclang-start ()
"Start SuperCollider process." "Start SuperCollider process."
@ -595,8 +591,7 @@ if PRINT-P is non-nil. Return STRING if successful, otherwise nil."
(let ((time (current-time)) (tick 10000) elt) (let ((time (current-time)) (tick 10000) elt)
(sclang-perform-command 'evalSCLang string time) (sclang-perform-command 'evalSCLang string time)
(while (and (> (decf tick) 0) (while (and (> (decf tick) 0)
(not (setq elt (find time sclang-eval-results (not (setq elt (assoc time sclang-eval-results))))
:key #'car :test #'equal))))
(accept-process-output proc 0 100)) (accept-process-output proc 0 100))
(if elt (if elt
(prog1 (if (eq (nth 1 elt) 'ok) (prog1 (if (eq (nth 1 elt) 'ok)