emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/emacsql 8be75b66b1 05/11: Use `and' instead of `when' if v


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 8be75b66b1 05/11: Use `and' instead of `when' if value matters
Date: Fri, 19 Jan 2024 19:00:24 -0500 (EST)

branch: elpa/emacsql
commit 8be75b66b17a93687d5a209e2be011e3fb911279
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Use `and' instead of `when' if value matters
---
 emacsql-compiler.el | 46 ++++++++++++++++++++++------------------------
 emacsql.el          | 12 ++++++------
 2 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/emacsql-compiler.el b/emacsql-compiler.el
index 8615c0a1b3..f74ed77e5e 100644
--- a/emacsql-compiler.el
+++ b/emacsql-compiler.el
@@ -210,16 +210,16 @@
 A parameter is a symbol that looks like $i1, $s2, $v3, etc. The
 letter refers to the type: identifier (i), scalar (s),
 vector (v), raw string (r), schema (S)."
-  (when (symbolp thing)
-    (let ((name (symbol-name thing)))
-      (when (string-match-p "^\\$[isvrS][0-9]+$" name)
-        (cons (1- (read (substring name 2)))
-              (cl-ecase (aref name 1)
-                (?i :identifier)
-                (?s :scalar)
-                (?v :vector)
-                (?r :raw)
-                (?S :schema)))))))
+  (and (symbolp thing)
+       (let ((name (symbol-name thing)))
+         (and (string-match-p "^\\$[isvrS][0-9]+$" name)
+              (cons (1- (read (substring name 2)))
+                    (cl-ecase (aref name 1)
+                      (?i :identifier)
+                      (?s :scalar)
+                      (?v :vector)
+                      (?r :raw)
+                      (?S :schema)))))))
 
 (defmacro emacsql-with-params (prefix &rest body)
   "Evaluate BODY, collecting parameters.
@@ -349,20 +349,18 @@ See `emacsql--generate-op-lookup-defun' for details."
   "Create format-string for an SQL operator.
 The format-string returned is intended to be used with `format'
 to create an SQL expression."
-  (when expr
-    (cl-labels ((replace-operand (x) (if (eq x :operand)
-                                         "%s"
-                                       x))
-                (to-format-string (e) (mapconcat #'replace-operand e "")))
-      (cond
-       ((and (eq arity :unary) (eql argument-count 1))
-        (to-format-string expr))
-       ((and (eq arity :binary) (>= argument-count 2))
-        (let ((result (reverse expr)))
-          (dotimes (_ (- argument-count 2))
-            (setf result (nconc (reverse expr) (cdr result))))
-          (to-format-string (nreverse result))))
-       (t (emacsql-error "Wrong number of operands for %s" op))))))
+  (and expr
+       (cl-labels ((replace-operand (x) (if (eq x :operand) "%s" x))
+                   (to-format-string (e) (mapconcat #'replace-operand e "")))
+         (cond
+          ((and (eq arity :unary) (eql argument-count 1))
+           (to-format-string expr))
+          ((and (eq arity :binary) (>= argument-count 2))
+           (let ((result (reverse expr)))
+             (dotimes (_ (- argument-count 2))
+               (setf result (nconc (reverse expr) (cdr result))))
+             (to-format-string (nreverse result))))
+          (t (emacsql-error "Wrong number of operands for %s" op))))))
 
 (defun emacsql--get-op-info (op argument-count parent-precedence-value)
   "Lookup SQL operator information for generating an SQL expression.
diff --git a/emacsql.el b/emacsql.el
index cfa8bb4dd3..9eb9c7002f 100644
--- a/emacsql.el
+++ b/emacsql.el
@@ -189,7 +189,7 @@ misnamed and obsolete accessor function."
 (cl-defmethod emacsql-wait ((connection emacsql-connection) &optional timeout)
   "Block until CONNECTION is waiting for further input."
   (let* ((real-timeout (or timeout emacsql-global-timeout))
-         (end (when real-timeout (+ (float-time) real-timeout))))
+         (end (and real-timeout (+ (float-time) real-timeout))))
     (while (and (or (null real-timeout) (< (float-time) end))
                 (not (emacsql-waiting-p connection)))
       (save-match-data
@@ -202,7 +202,7 @@ misnamed and obsolete accessor function."
 
 (defun emacsql-compile (connection sql &rest args)
   "Compile s-expression SQL for CONNECTION into a string."
-  (let* ((mask (when connection (emacsql-types connection)))
+  (let* ((mask (and connection (emacsql-types connection)))
          (emacsql-type-map (or mask emacsql-type-map)))
     (concat (apply #'emacsql-format (emacsql-prepare sql) args) ";")))
 
@@ -346,7 +346,7 @@ compile time. For example, in the expression below the 
variables
 Each column must be a plain symbol, no expressions allowed here."
   (declare (indent 2))
   (let ((sql (if (vectorp sql-and-args) sql-and-args (car sql-and-args)))
-        (args (unless (vectorp sql-and-args) (cdr sql-and-args))))
+        (args (and (not (vectorp sql-and-args)) (cdr sql-and-args))))
     (cl-assert (eq :select (elt sql 0)))
     (let ((vars (elt sql 1)))
       (when (eq '* vars)
@@ -434,9 +434,9 @@ A prefix argument causes the SQL to be printed into the 
current buffer."
     (save-excursion
       (beginning-of-defun)
       (let ((containing-sexp (elt (parse-partial-sexp (point) start) 1)))
-        (when containing-sexp
-          (goto-char containing-sexp)
-          (looking-at "\\["))))))
+        (and containing-sexp
+             (progn (goto-char containing-sexp)
+                    (looking-at "\\[")))))))
 
 (defun emacsql--calculate-vector-indent (fn &optional parse-start)
   "Don't indent vectors in `emacs-lisp-mode' like lists."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]