]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-parser.el
emacs: Use 'unless' instead of 'when' and 'not'
[notmuch] / emacs / notmuch-parser.el
index d59c0e1cc22727d60454ac0a79a04f63a99cf21d..fbcfc2efb4e6ca624a17198c4b84fc37669e5ec5 100644 (file)
@@ -1,4 +1,4 @@
-;; notmuch-parser.el --- streaming S-expression parser
+;;; notmuch-parser.el --- streaming S-expression parser
 ;;
 ;; Copyright © Austin Clements
 ;;
 ;; General Public License for more details.
 ;;
 ;; You should have received a copy of the GNU General Public License
-;; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.
+;; along with Notmuch.  If not, see <https://www.gnu.org/licenses/>.
 ;;
 ;; Authors: Austin Clements <aclements@csail.mit.edu>
 
-(require 'cl)
+;;; Code:
+
+(eval-when-compile (require 'cl-lib))
 
 (defun notmuch-sexp-create-parser ()
   "Return a new streaming S-expression parser.
@@ -36,7 +38,6 @@ can return 'retry to indicate that not enough input is available.
 The parser always consumes input from point in the current
 buffer.  Hence, the caller is allowed to delete any data before
 point and may resynchronize after an error by moving point."
-
   (vector 'notmuch-sexp-parser
          ;; List depth
          0
@@ -58,7 +59,6 @@ parser is currently inside a list and the next token ends the
 list, this moves point just past the terminator and returns 'end.
 Otherwise, this moves point to just past the end of the value and
 returns the value."
-
   (skip-chars-forward " \n\r\t")
   (cond ((eobp) 'retry)
        ((= (char-after) ?\))
@@ -68,7 +68,7 @@ returns the value."
             ;; error to be consistent with all other code paths.
             (read (current-buffer))
           ;; Go up a level and return an end token
-          (decf (notmuch-sexp--depth sp))
+          (cl-decf (notmuch-sexp--depth sp))
           (forward-char)
           'end))
        ((= (char-after) ?\()
@@ -78,7 +78,7 @@ returns the value."
         ;; parse, extend the partial parse to figure out when we
         ;; have a complete list.
         (catch 'return
-          (when (null (notmuch-sexp--partial-state sp))
+          (unless (notmuch-sexp--partial-state sp)
             (let ((start (point)))
               (condition-case nil
                   (throw 'return (read (current-buffer)))
@@ -92,8 +92,8 @@ returns the value."
                                  (notmuch-sexp--partial-state sp)))
                      ;; A complete value is available if we've
                      ;; reached depth 0.
-                     (depth (first new-state)))
-                (assert (>= depth 0))
+                     (depth (car new-state)))
+                (cl-assert (>= depth 0))
                 (if (= depth 0)
                     ;; Reset partial parse state
                     (setf (notmuch-sexp--partial-state sp) nil
@@ -132,12 +132,11 @@ a list, it moves point past the token that opens the list and
 returns t.  Later calls to `notmuch-sexp-read' will return the
 elements inside the list.  If the input in buffer is not the
 beginning of a list, throw invalid-read-syntax."
-
   (skip-chars-forward " \n\r\t")
   (cond ((eobp) 'retry)
        ((= (char-after) ?\()
         (forward-char)
-        (incf (notmuch-sexp--depth sp))
+        (cl-incf (notmuch-sexp--depth sp))
         t)
        (t
         ;; Skip over the bad character like `read' does
@@ -149,7 +148,6 @@ beginning of a list, throw invalid-read-syntax."
 
 Moves point to the beginning of any trailing data or to the end
 of the buffer if there is only trailing whitespace."
-
   (skip-chars-forward " \n\r\t")
   (unless (eobp)
     (error "Trailing garbage following expression")))
@@ -171,7 +169,6 @@ complete value in the list.  It operates incrementally and should
 be called whenever the input buffer has been extended with
 additional data.  The caller just needs to ensure it does not
 move point in the input buffer."
-
   ;; Set up the initial state
   (unless (local-variable-p 'notmuch-sexp--parser)
     (set (make-local-variable 'notmuch-sexp--parser)
@@ -179,7 +176,7 @@ move point in the input buffer."
     (set (make-local-variable 'notmuch-sexp--state) 'begin))
   (let (done)
     (while (not done)
-      (case notmuch-sexp--state
+      (cl-case notmuch-sexp--state
        (begin
         ;; Enter the list
         (if (eq (notmuch-sexp-begin-list notmuch-sexp--parser) 'retry)
@@ -188,7 +185,7 @@ move point in the input buffer."
        (result
         ;; Parse a result
         (let ((result (notmuch-sexp-read notmuch-sexp--parser)))
-          (case result
+          (cl-case result
             (retry (setq done t))
             (end   (setq notmuch-sexp--state 'end))
             (t     (with-current-buffer result-buffer
@@ -202,6 +199,4 @@ move point in the input buffer."
 
 (provide 'notmuch-parser)
 
-;; Local Variables:
-;; byte-compile-warnings: (not cl-functions)
-;; End:
+;;; notmuch-parser.el ends here