emacs-devel
[Top][All Lists]
Advanced

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

Re: [ELPA] New Package: phpinspect.el


From: Stefan Monnier
Subject: Re: [ELPA] New Package: phpinspect.el
Date: Tue, 15 Aug 2023 18:03:53 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

> And here I was thinking that I had fixed all of the byte compilation
>  problems.. Turns out it was only working because I byte compiled everything
>  within the same Emacs session.

:-)

> I made some changes and think things should
> be in order now. At least, the following shell script doesn't seem to
> result in any errors:
>
> for file in ./*.el; do
>     cask emacs -batch -L . --eval '(setq byte-compile-error-on-warn t)' -f
> batch-byte-compile "$file" || break
> done

Yay!
And you even saved kittens along the way!!!

> I see some warnings in your log that concern files in the "benchmark" and
> "test" directories.  These files are not required for the package to
> function.  Can these be excluded from the ELPA build somehow?

The log was for a compilation from the Git, not from the ELPA tarball,
but you can indeed exclude them from the ELPA tarball by listing those
elements in the `.elpaignore` file at the root of your package.

You can check the result at http://elpa.gnu.org/devel/phpinspect.html
(once it builds a tarball successfully).

> I have seen some projects use a "lisp" directory for their source
> code, is that the recommended approach for this?

No, it's unrelated.

BTW, here's another set of patches in you're interested.


        Stefan
diff --git a/benchmarks/appendage.el b/benchmarks/appendage.el
index 3cb48477b0..6c8a06f880 100644
--- a/benchmarks/appendage.el
+++ b/benchmarks/appendage.el
@@ -25,29 +25,29 @@
 
 (message "20000 appendages using nconc")
 (garbage-collect)
-(benchmark
- 1 '(let (list)
-      (dotimes (i 20000)
-        (setq list (nconc list (list i))))
+(benchmark-run 1
+  (let (list)
+    (dotimes (i 20000)
+      (setq list (nconc list (list i))))
 
-      list))
+    list))
 
 (message "20000 appendages using push + nreverse")
 (garbage-collect)
-(benchmark
- 1 '(let (list)
-      (dotimes (i 20000)
-        (push i list))
+(benchmark-run 1
+  (let (list)
+    (dotimes (i 20000)
+      (push i list))
 
-      (nreverse list)))
+    (nreverse list)))
 
 (message "20000 appendages using rear pointer")
 (garbage-collect)
-(benchmark
- 1 '(let* ((list (cons nil nil))
-           (rear list))
+(benchmark-run 1
+  (let* ((list (cons nil nil))
+         (rear list))
 
-      (dotimes (i 20000)
-        (setq rear (setcdr rear (cons i nil))))
+    (dotimes (i 20000)
+      (setq rear (setcdr rear (cons i nil))))
 
-      (cdr list)))
+    (cdr list)))
diff --git a/benchmarks/parse-file.el b/benchmarks/parse-file.el
index e135ce21c0..1416eedbb8 100644
--- a/benchmarks/parse-file.el
+++ b/benchmarks/parse-file.el
@@ -30,20 +30,20 @@
    (current-buffer)
    (point-max)))
 
-(let ((here (file-name-directory (or load-file-name buffer-file-name))))
+(let ((here (file-name-directory (macroexp-file-name))))
 
   (with-temp-buffer
-    (insert-file-contents (concat here "/Response.php"))
+    (insert-file-contents (expand-file-name "Response.php" here))
 
     (message "Incremental parse (warmup):")
     (phpinspect-with-parse-context (phpinspect-make-pctx :incremental t :bmap 
(phpinspect-make-bmap))
-      (benchmark 1 '(phpinspect-parse-current-buffer)))
+      (benchmark-run 1 (phpinspect-parse-current-buffer)))
 
     (let ((bmap (phpinspect-make-bmap))
           (bmap2 (phpinspect-make-bmap)))
       (message "Incremental parse:")
       (phpinspect-with-parse-context (phpinspect-make-pctx :incremental t 
:bmap bmap)
-        (benchmark 1 '(phpinspect-parse-current-buffer)))
+        (benchmark-run 1 (phpinspect-parse-current-buffer)))
 
       (garbage-collect)
 
@@ -52,7 +52,7 @@
                                                            :bmap bmap2
                                                            :previous-bmap bmap
                                                            :edtrack 
(phpinspect-make-edtrack))
-        (benchmark 1 '(phpinspect-parse-current-buffer)))
+        (benchmark-run 1 (phpinspect-parse-current-buffer)))
 
       (garbage-collect)
 
@@ -61,7 +61,7 @@
                                                            :bmap 
(phpinspect-make-bmap)
                                                            :previous-bmap bmap2
                                                            :edtrack 
(phpinspect-make-edtrack))
-        (benchmark 1 '(phpinspect-parse-current-buffer)))
+        (benchmark-run 1 (phpinspect-parse-current-buffer)))
 
       (garbage-collect)
 
@@ -75,13 +75,13 @@
         (message "Incremental parse after buffer edit:")
         ;; Removes closing curly brace of __construct
         (goto-char 9062)
-        (delete-backward-char 1)
+        (delete-char -1)
 
         (garbage-collect)
 
         (phpinspect-edtrack-register-edit edtrack 9061 9061 1)
         (phpinspect-with-parse-context (phpinspect-make-pctx :bmap bmap-after 
:incremental t :previous-bmap bmap :edtrack edtrack)
-          (benchmark 1 '(phpinspect-parse-current-buffer)))
+          (benchmark-run 1 (phpinspect-parse-current-buffer)))
 
         (phpinspect-edtrack-clear edtrack)
         (insert "{")
@@ -98,22 +98,22 @@
                                                              :incremental t
                                                              :previous-bmap 
bmap-after
                                                              :edtrack edtrack)
-          (benchmark 1 '(phpinspect-parse-current-buffer)))
+          (benchmark-run 1 (phpinspect-parse-current-buffer)))
 
         ;; (save-current-buffer
         ;;   (profiler-stop)
         ;;   (profiler-report)
-        ;;   (profiler-report-write-profile (concat here "/profile.txt")))
+        ;;   (profiler-report-write-profile (expand-file-name "profile.txt" 
here)))
         )))
 
   (with-temp-buffer
-    (insert-file-contents (concat here "/Response.php"))
+    (insert-file-contents (expand-file-name "Response.php" here))
 
     (garbage-collect)
     (message "Bare (no token reuse) parse (warmup):")
-    (benchmark 1 '(phpinspect-parse-current-buffer))
+    (benchmark-run 1 (phpinspect-parse-current-buffer))
 
 
     (garbage-collect)
     (message "Bare (no token reuse) parse:")
-    (benchmark 1 '(phpinspect-parse-current-buffer))))
+    (benchmark-run 1 (phpinspect-parse-current-buffer))))
diff --git a/benchmarks/splay-tree.el b/benchmarks/splay-tree.el
index ffd8978f5e..9fc4d9eb38 100644
--- a/benchmarks/splay-tree.el
+++ b/benchmarks/splay-tree.el
@@ -25,49 +25,49 @@
 
 (require 'phpinspect-splayt)
 
-(let ((here (file-name-directory (or load-file-name buffer-file-name)))
+(let ((here (file-name-directory (macroexp-file-name)))
       (tree (phpinspect-make-splayt)))
   (message "Splay tree 10000 insertions:")
   (garbage-collect)
-  (benchmark
-   1 '(dotimes (i 10000)
-        (phpinspect-splayt-insert tree i 'value)))
+  (benchmark-run 1
+    (dotimes (i 10000)
+      (phpinspect-splayt-insert tree i 'value)))
 
   (message "Splay tree 10000 lookups:")
   (garbage-collect)
-  (benchmark
-   1 '(dotimes (i 10000)
-        (phpinspect-splayt-find tree i)))
+  (benchmark-run 1
+    (dotimes (i 10000)
+      (phpinspect-splayt-find tree i)))
 
   (message "Splay tree 10000 items traversal:")
   (garbage-collect)
-  (benchmark
-   1 '(phpinspect-splayt-traverse (i tree)
-        nil))
+  (benchmark-run 1
+    (phpinspect-splayt-traverse (i tree)
+                                nil))
 
   (message "Splay tree 10000 items LR traversal:")
   (garbage-collect)
-  (benchmark
-   1 '(phpinspect-splayt-traverse-lr (i tree)
-        nil)))
+  (benchmark-run 1
+    (phpinspect-splayt-traverse-lr (i tree)
+                                   nil)))
 
 
 (let (map)
   (message "Hashtable 10000 insertions:")
   (garbage-collect)
-  (benchmark
-   1 '(progn
-        (setq map (make-hash-table :test #'eq :size 10000 :rehash-size 1.5))
-        (dotimes (i 10000)
-        (puthash i 'value map))))
+  (benchmark-run
+   1 (progn
+       (setq map (make-hash-table :test #'eq :size 10000 :rehash-size 1.5))
+       (dotimes (i 10000)
+         (puthash i 'value map))))
 
   (message "Hashtable 10000 lookups:")
   (garbage-collect)
-  (benchmark
-   1 '(dotimes (i 10000)
-        (gethash i map)))
+  (benchmark-run 1
+    (dotimes (i 10000)
+      (gethash i map)))
 
   (message "Hashtable 10000 iterations:")
   (garbage-collect)
-  (benchmark
-   1 '(maphash (lambda (k v) nil) map)))
+  (benchmark-run 1
+    (maphash (lambda (_k _v) nil) map)))
diff --git a/phpinspect-parse-context.el b/phpinspect-parse-context.el
index f5c6401e1f..e56e5d1687 100644
--- a/phpinspect-parse-context.el
+++ b/phpinspect-parse-context.el
@@ -36,7 +36,7 @@ parsing. Usually used in combination with
   "Parser Context"
   (incremental nil)
   (meta-iterator nil)
-  (interrupt-threshold (time-convert '(0 0 2000 0))
+  (interrupt-threshold (time-convert '(0 0 2000 0) t)
                        :documentation
                        "After how much time `interrupt-predicate'
 should be polled. This is 2ms by default.")
diff --git a/phpinspect-parser.el b/phpinspect-parser.el
index ccef0e2f04..211dae59a0 100644
--- a/phpinspect-parser.el
+++ b/phpinspect-parser.el
@@ -144,116 +144,116 @@ HANDLERS must be a list of symbols referring to existing
 parser handlers defined using `phpinspect-defhandler'.
 
 DELIMITER-PREDICATE must be a function.  It is passed the last
-parsed token after every handler iteration.  If it evaluates to
+parsed token after every handler iteration.  If it returns
 something other than nil, parsing is deemed completed and the
 loop exits.  An example use case of this is to determine the end
 of a statement.  You can use `phpinspect-terminator-p` as
 delimiter predicate and have parsing stop when the last parsed
 token is \";\", which marks the end of a statement in PHP."
-    (let ((delimiter-predicate (if (symbolp delimiter-predicate)
-                                   `(quote ,delimiter-predicate)
-                                 delimiter-predicate)))
-      `(defsubst ,(phpinspect-parser-func-name name "simple") (buffer 
max-point &optional skip-over continue-condition &rest _ignored)
-         (with-current-buffer buffer
-           (let* ((tokens (cons ,tree-type nil))
-                  (tokens-rear tokens)
-                  token
-                  (delimiter-predicate (when (functionp ,delimiter-predicate) 
,delimiter-predicate)))
-             (when skip-over (forward-char skip-over))
+    (cl-assert (symbolp delimiter-predicate))
+    ;; FIXME: Why `defsubst'?  Since there's a loop in this function,
+    ;; it seems unlikely that the function call overhead will make
+    ;; any measurable performance difference.
+    `(defsubst ,(phpinspect-parser-func-name name "simple") (buffer max-point 
&optional skip-over continue-condition &rest _ignored)
+       (with-current-buffer buffer
+         (let* ((tokens (cons ,tree-type nil))
+                (tokens-rear tokens)
+                token)
+           (when skip-over (forward-char skip-over))
+           (while (and (< (point) max-point)
+                       (if continue-condition (funcall continue-condition) t)
+                       (not ,(if delimiter-predicate
+                                   `(,delimiter-predicate (car (last tokens)))
+                                 nil)))
+             (cond ,@(mapcar
+                      (lambda (handler)
+                        `((looking-at (,(phpinspect-handler-regexp-func-name 
handler)))
+                          (setq token (,(phpinspect-handler-func-name handler) 
(match-string 0) max-point))
+                          (when token
+                            (setq tokens-rear (setcdr tokens-rear (cons token 
nil))))))
+                      handlers)
+                   (t (forward-char))))
+
+           ;; Return
+           tokens))))
+
+
+  (defun phpinspect-make-incremental-parser-function (name tree-type handlers 
&optional delimiter-predicate)
+    "Like `phpinspect-make-parser-function', but returned function
+is able to reuse an already parsed tree."
+    (cl-assert (symbolp delimiter-predicate))
+    ;; FIXME: Why `defsubst'?  Since there's a loop in this function,
+    ;; it seems unlikely that the function call overhead will make
+    ;; any measurable performance difference.
+    `(defsubst ,(phpinspect-parser-func-name name "incremental") (context 
buffer max-point &optional skip-over continue-condition root)
+       (with-current-buffer buffer
+         (let* ((tokens (cons ,tree-type nil))
+                (tokens-rear tokens)
+                (root-start (point))
+                (bmap (phpinspect-pctx-bmap context))
+                (previous-bmap (phpinspect-pctx-previous-bmap context))
+                (edtrack (phpinspect-pctx-edtrack context))
+                (taint-iterator (when edtrack 
(phpinspect-edtrack-make-taint-iterator edtrack)))
+                (check-interrupt (phpinspect-pctx-interrupt-predicate context))
+
+                ;; Loop variables
+                (start-position)
+                (original-position)
+                (current-end-position)
+                (existing-meta)
+                (delta)
+                (token))
+           (when skip-over (forward-char skip-over))
+           (phpinspect-pctx-save-whitespace context
              (while (and (< (point) max-point)
                          (if continue-condition (funcall continue-condition) t)
-                         (not (if delimiter-predicate
-                                  (funcall delimiter-predicate (car (last 
tokens)))
-                                nil)))
-               (cond ,@(mapcar
+                         (not ,(if delimiter-predicate
+                                   `(,delimiter-predicate (car (last tokens)))
+                                 nil)))
+               (when check-interrupt
+                 (phpinspect-pctx-check-interrupt context))
+
+               (setq start-position (point))
+               (cond ((and previous-bmap edtrack
+                           (setq existing-meta
+                                 (phpinspect-bmap-token-starting-at
+                                  previous-bmap
+                                  (setq original-position
+                                        
(phpinspect-edtrack-original-position-at-point edtrack start-position))))
+                           (not (or (phpinspect-root-p (phpinspect-meta-token 
existing-meta))
+                                    
(phpinspect-taint-iterator-token-is-tainted-p taint-iterator existing-meta))))
+                      (setq delta (- start-position original-position)
+                            current-end-position (+ (phpinspect-meta-end 
existing-meta) delta)
+                            token (phpinspect-meta-token existing-meta))
+
+                      ;;(message "Reusing token  %s at point %s" 
(phpinspect-meta-string existing-meta) (point))
+                      ;; Re-register existing token
+                      (phpinspect-bmap-overlay
+                       bmap previous-bmap existing-meta delta
+                       (phpinspect-pctx-consume-whitespace context))
+
+                      (goto-char current-end-position)
+
+                      ;; Skip over whitespace after so that we don't do a full
+                      ;; run down all of the handlers during the next iteration
+                      (when (looking-at (phpinspect-handler-regexp whitespace))
+                        (,(phpinspect-handler-func-name 'whitespace) 
(match-string 0))))
+                     ,@(mapcar
                         (lambda (handler)
                           `((looking-at (,(phpinspect-handler-regexp-func-name 
handler)))
                             (setq token (,(phpinspect-handler-func-name 
handler) (match-string 0) max-point))
                             (when token
-                              (setq tokens-rear (setcdr tokens-rear (cons 
token nil))))))
+                              (phpinspect-pctx-register-token context token 
start-position (point)))))
                         handlers)
-                     (t (forward-char))))
-
-             ;; Return
-             tokens)))))
-
-
-  (defun phpinspect-make-incremental-parser-function (name tree-type handlers 
&optional delimiter-predicate)
-    "Like `phpinspect-make-parser-function', but returned function
-is able to reuse an already parsed tree."
-    (let ((delimiter-predicate (if (symbolp delimiter-predicate)
-                                   `(quote ,delimiter-predicate)
-                                 delimiter-predicate)))
-      `(defsubst ,(phpinspect-parser-func-name name "incremental") (context 
buffer max-point &optional skip-over continue-condition root)
-         (with-current-buffer buffer
-           (let* ((tokens (cons ,tree-type nil))
-                  (tokens-rear tokens)
-                  (root-start (point))
-                  (bmap (phpinspect-pctx-bmap context))
-                  (previous-bmap (phpinspect-pctx-previous-bmap context))
-                  (edtrack (phpinspect-pctx-edtrack context))
-                  (taint-iterator (when edtrack 
(phpinspect-edtrack-make-taint-iterator edtrack)))
-                  (check-interrupt (phpinspect-pctx-interrupt-predicate 
context))
-
-                  ;; Loop variables
-                  (start-position)
-                  (original-position)
-                  (current-end-position)
-                  (existing-meta)
-                  (delta)
-                  (token)
-                  (delimiter-predicate (when (functionp ,delimiter-predicate) 
,delimiter-predicate)))
-             (when skip-over (forward-char skip-over))
-             (phpinspect-pctx-save-whitespace context
-               (while (and (< (point) max-point)
-                           (if continue-condition (funcall continue-condition) 
t)
-                           (not (if delimiter-predicate
-                                    (funcall delimiter-predicate (car (last 
tokens)))
-                                  nil)))
-                 (when check-interrupt
-                   (phpinspect-pctx-check-interrupt context))
-
-                 (setq start-position (point))
-                 (cond ((and previous-bmap edtrack
-                             (setq existing-meta
-                                   (phpinspect-bmap-token-starting-at
-                                    previous-bmap
-                                    (setq original-position
-                                          
(phpinspect-edtrack-original-position-at-point edtrack start-position))))
-                             (not (or (phpinspect-root-p 
(phpinspect-meta-token existing-meta))
-                                      
(phpinspect-taint-iterator-token-is-tainted-p taint-iterator existing-meta))))
-                        (setq delta (- start-position original-position)
-                              current-end-position (+ (phpinspect-meta-end 
existing-meta) delta)
-                              token (phpinspect-meta-token existing-meta))
-
-                        ;;(message "Reusing token  %s at point %s" 
(phpinspect-meta-string existing-meta) (point))
-                        ;; Re-register existing token
-                        (phpinspect-bmap-overlay
-                         bmap previous-bmap existing-meta delta
-                         (phpinspect-pctx-consume-whitespace context))
-
-                        (goto-char current-end-position)
-
-                        ;; Skip over whitespace after so that we don't do a 
full
-                        ;; run down all of the handlers during the next 
iteration
-                        (when (looking-at (phpinspect-handler-regexp 
whitespace))
-                          (,(phpinspect-handler-func-name 'whitespace) 
(match-string 0))))
-                       ,@(mapcar
-                          (lambda (handler)
-                            `((looking-at 
(,(phpinspect-handler-regexp-func-name handler)))
-                              (setq token (,(phpinspect-handler-func-name 
handler) (match-string 0) max-point))
-                              (when token
-                                (phpinspect-pctx-register-token context token 
start-position (point)))))
-                          handlers)
-                       (t (forward-char)))
-                 (when token
-                   (setq tokens-rear (setcdr tokens-rear (cons token nil)))
-                   (setq token nil))))
-             (when root
-               (phpinspect-pctx-register-token context tokens root-start 
(point)))
-
-             ;; Return
-             tokens)))))
+                     (t (forward-char)))
+               (when token
+                 (setq tokens-rear (setcdr tokens-rear (cons token nil)))
+                 (setq token nil))))
+           (when root
+             (phpinspect-pctx-register-token context tokens root-start 
(point)))
+
+           ;; Return
+           tokens))))
 
   (cl-defstruct (phpinspect-parser (:constructor phpinspect-make-parser))
     (name 'root
diff --git a/phpinspect-pipeline.el b/phpinspect-pipeline.el
index c9c7cf2085..4e45150807 100644
--- a/phpinspect-pipeline.el
+++ b/phpinspect-pipeline.el
@@ -275,6 +275,7 @@ directories."
                (setq key (pop parameters)
                      value (pop parameters))
                (setq key (intern (string-replace ":with-" ":" (symbol-name 
key))))
+               ;; FIXME: There's an O(N²) complexity here :-(
                (setq construct-params (nconc construct-params (list key 
value)))))
            (push (apply #'phpinspect--make-pipeline-step `(,@construct-params 
:name ,name))
                  steps)))
diff --git a/phpinspect-splayt.el b/phpinspect-splayt.el
index 339bf3739a..15eac4e6f4 100644
--- a/phpinspect-splayt.el
+++ b/phpinspect-splayt.el
@@ -279,13 +279,15 @@ apeared to be a little more performant than using `let'."
        nil)))
 
 (defmacro phpinspect-splayt-traverse (place-and-splayt &rest body)
-  "Traverse splay tree in cadr of PLACE-AND-SPLAYT, executing BODY.
+  "Traverse SPLAYT, executing BODY.
 
-The car of PLACE-AND-SPLAYT is assigned the value of each node.
+The PLACE is assigned the value of each node.
 
-Traversal is breadth-first to take advantage of the splay trees
+Traversal is breadth-first to take advantage of the splay trees'
 main benefit: the most accessed interval of keys is likely to be
-near the top of the tee."
+near the top of the tee.
+
+(fn (PLACE SPLAYT) BODY...)"
   (declare (indent 1))
  (let* ((current (gensym))
          (code `(phpinspect-splayt-node-traverse
@@ -293,8 +295,15 @@ near the top of the tee."
                   (setf ,(car place-and-splayt) (phpinspect-splayt-node-value 
,current))
                   ,@body)))
     (if (symbolp (car place-and-splayt))
+        ;; FIXME: You first use `let' to "declare" the var and then
+        ;; initialize it inside `code'.  This is marginally inefficient,
+        ;; but more importantly it means that if the var is not used in
+        ;; the rest of `code' the compiler will either complain that the var
+        ;; is not used or (if it starts with an underscore) complain that
+        ;; it's used!
         `(let (,(car place-and-splayt))
            ,code)
+      ;; FIXME: This branch is never used!
       code)))
 
 (defmacro phpinspect-splayt-node-traverse-lr (place-and-node &rest body)
diff --git a/phpinspect-util.el b/phpinspect-util.el
index 3c04f7f7fb..05c1f11dcc 100644
--- a/phpinspect-util.el
+++ b/phpinspect-util.el
@@ -51,7 +51,8 @@ PHP. Used to optimize string comparison.")
 
   (inline-quote
    (progn
-     (add-to-list 'phpinspect-log-groups (cons (or load-file-name 
buffer-file-name) ,group) nil #'equal))))
+     (add-to-list 'phpinspect-log-groups
+                  (cons (macroexp-file-name) ,group)))))
 
 (defun phpinspect-log-group-enabled-p (group)
   (seq-find (lambda (cons)
@@ -61,7 +62,8 @@ PHP. Used to optimize string comparison.")
 (phpinspect--declare-log-group 'bam)
 
 (defmacro phpinspect--log (&rest args)
-  (let ((log-group (alist-get (or load-file-name buffer-file-name) 
phpinspect-log-groups nil nil #'string=)))
+  (let ((log-group (alist-get (macroexp-file-name)
+                              phpinspect-log-groups nil nil #'string=)))
     `(when (and phpinspect--debug
                 (or (not phpinspect-enabled-log-groups)
                     ,(when log-group
@@ -77,7 +79,8 @@ PHP. Used to optimize string comparison.")
 (defun phpinspect-filter-logs (group-name)
   (interactive (list (completing-read "Log group: "
                                       (mapcar (lambda (g) (symbol-name (cdr 
g)))
-                                              phpinspect-log-groups) nil t)))
+                                              phpinspect-log-groups)
+                                      nil t)))
   (add-to-list 'phpinspect-enabled-log-groups (intern group-name)))
 
 (defun phpinspect-unfilter-logs ()
diff --git a/phpinspect.el b/phpinspect.el
index 6785f63e38..280193423e 100644
--- a/phpinspect.el
+++ b/phpinspect.el
@@ -173,57 +173,57 @@ Example configuration if you already have a completion
 UI (Company, Corfu) setup that can take advantage of completion
 at point (capf) functions:
 
-(defun my-php-personal-hook ()
-  ;; Shortcut to add use statements for classes you use.
-  (define-key php-mode-map (kbd \"C-c u\") #\\='phpinspect-fix-imports)
-
-  ;; Shortcuts to quickly search/open files of PHP classes.
-  ;; You can make these local to php-mode, but making them global
-  ;; like this makes them work in other modes/filetypes as well, which
-  ;; can be handy when jumping between templates, config files and PHP code.
-  (global-set-key (kbd \"C-c a\") #\\='phpinspect-find-class-file)
-  (global-set-key (kbd \"C-c c\") #\\='phpinspect-find-own-class-file)
-
-  ;; Enable phpinspect-mode
-  (phpinspect-mode))
-
-(add-hook 'php-mode-hook #'my-php-personal-hook)
+    (defun my-php-personal-hook ()
+      ;; Shortcut to add use statements for classes you use.
+      (define-key php-mode-map (kbd \"C-c u\") #\\='phpinspect-fix-imports)
+    
+      ;; Shortcuts to quickly search/open files of PHP classes.
+      ;; You can make these local to php-mode, but making them global
+      ;; like this makes them work in other modes/filetypes as well, which
+      ;; can be handy when jumping between templates, config files and PHP 
code.
+      (global-set-key (kbd \"C-c a\") #\\='phpinspect-find-class-file)
+      (global-set-key (kbd \"C-c c\") #\\='phpinspect-find-own-class-file)
+    
+      ;; Enable phpinspect-mode
+      (phpinspect-mode))
+    
+    (add-hook \\='php-mode-hook #\\='my-php-personal-hook)
 
 
 Example configuration for `company-mode':
 
-  (defun my-php-personal-hook ()
-    ;; Assuming you already have company-mode enabled, these settings
-    ;; add some IDE-like flair to it. This is of course not required, do
-    ;; with it what you like.
-    (setq-local company-minimum-prefix-length 0)
-    (setq-local company-tooltip-align-annotations t)
-    (setq-local company-idle-delay 0.1)
-
-    ;; If you don't have company-mode enabled by default, uncomment this line:
-    ;; (company-mode)
-
-    ;; By default, phpinspect-mode adds itself as a backend to
-    ;; the `company-backends' of the current buffer. You can completely
-    ;; disable all other backends with the statement below.
-    (setq-local company-backends '(phpinspect-company-backend))
-
-    ;; Shortcut to add use statements for classes you use.
-    (define-key php-mode-map (kbd \"C-c u\") 'phpinspect-fix-imports)
-
-    ;; Shortcuts to quickly search/open files of PHP classes.
-    ;; You can make these local to php-mode, but making them global
-    ;; like this makes them work in other modes/filetypes as well, which
-    ;; can be handy when jumping between templates, config files and PHP code.
-    (global-set-key (kbd \"C-c a\") 'phpinspect-find-class-file)
-    (global-set-key (kbd \"C-c c\") 'phpinspect-find-own-class-file)
-
-    ;; Enable phpinspect-mode
-    (phpinspect-mode))
-
-  (add-hook 'php-mode-hook #'my-php-personal-hook)
-
-;; End example configuration."
+    (defun my-php-personal-hook ()
+      ;; Assuming you already have company-mode enabled, these settings
+      ;; add some IDE-like flair to it. This is of course not required, do
+      ;; with it what you like.
+      (setq-local company-minimum-prefix-length 0)
+      (setq-local company-tooltip-align-annotations t)
+      (setq-local company-idle-delay 0.1)
+    
+      ;; If you don't have company-mode enabled by default, uncomment this 
line:
+      ;; (company-mode)
+    
+      ;; By default, phpinspect-mode adds itself as a backend to
+      ;; the `company-backends' of the current buffer. You can completely
+      ;; disable all other backends with the statement below.
+      (setq-local company-backends \\='(phpinspect-company-backend))
+    
+      ;; Shortcut to add use statements for classes you use.
+      (define-key php-mode-map (kbd \"C-c u\") #\\='phpinspect-fix-imports)
+    
+      ;; Shortcuts to quickly search/open files of PHP classes.
+      ;; You can make these local to php-mode, but making them global
+      ;; like this makes them work in other modes/filetypes as well, which
+      ;; can be handy when jumping between templates, config files and PHP 
code.
+      (global-set-key (kbd \"C-c a\") #\\='phpinspect-find-class-file)
+      (global-set-key (kbd \"C-c c\") #\\='phpinspect-find-own-class-file)
+    
+      ;; Enable phpinspect-mode
+      (phpinspect-mode))
+    
+    (add-hook \\='php-mode-hook #\\='my-php-personal-hook)
+
+    ;; End example configuration."
   :after-hook (phpinspect--mode-function))
 
 (defun phpinspect--suggest-at-point ()
diff --git a/test/phpinspect-test-env.el b/test/phpinspect-test-env.el
index 6bb0aef0da..8325721af8 100644
--- a/test/phpinspect-test-env.el
+++ b/test/phpinspect-test-env.el
@@ -2,6 +2,7 @@
 
 (require 'phpinspect-worker)
 (require 'phpinspect-cache)
+(require 'phpinspect-parser)
 
 ;; Make sure that the worker is running. TODO: fully encapsulate the worker the
 ;; data types that are used in tests so that we don't depend on some global
@@ -10,18 +11,12 @@
 (phpinspect-purge-cache)
 
 (defvar phpinspect-test-directory
-  (file-name-directory
-   (or load-file-name
-       buffer-file-name))
+  (file-name-directory (macroexp-file-name))
   "Directory that phpinspect tests reside in.")
 
 
 (defvar phpinspect-test-php-file-directory
-  (concat
-   (file-name-directory
-    (or load-file-name
-        buffer-file-name))
-   "/fixtures")
+  (expand-file-name "fixtures" phpinspect-test-directory)
   "Directory with syntax trees of example PHP files.")
 
 (defun phpinspect-test-read-fixture-data (name)
@@ -32,7 +27,7 @@
 (defun phpinspect-test-read-fixture-serialization (name)
   (with-temp-buffer
     (insert-file-contents-literally (concat phpinspect-test-php-file-directory 
"/" name ".eld"))
-    (eval (read (current-buffer)))))
+    (eval (read (current-buffer)) t)))
 
 (defun phpinspect-test-parse-fixture-code (name)
   (phpinspect-parse-file
diff --git a/test/phpinspect-test.el b/test/phpinspect-test.el
index 74435e30d1..aa82c488e3 100644
--- a/test/phpinspect-test.el
+++ b/test/phpinspect-test.el
@@ -27,8 +27,8 @@
 (require 'phpinspect)
 
 (require 'phpinspect-test-env
-         (concat (file-name-directory (or load-file-name buffer-file-name))
-                 "phpinspect-test-env.el"))
+         (expand-file-name "phpinspect-test-env.el"
+                           (file-name-directory (macroexp-file-name))))
 
 (ert-deftest phpinspect-get-variable-type-in-block ()
   (let* ((code "class Foo { function a(\\Thing $baz) { $foo = new 
\\DateTime(); $bar = $foo; Whatever comes after don't matter.")
diff --git a/test/test-autoload.el b/test/test-autoload.el
index 7f51a22020..42eb08db45 100644
--- a/test/test-autoload.el
+++ b/test/test-autoload.el
@@ -27,6 +27,7 @@
 (require 'ert)
 (require 'phpinspect-fs)
 (require 'phpinspect-autoload)
+(require 'phpinspect-resolvecontext)
 
 (ert-deftest phpinspect-filename-to-typename ()
   (should (eq (phpinspect-intern-name "\\Foo\\Bar") 
(phpinspect-filename-to-typename "src/" "src/Foo////////Bar.php")))
@@ -36,6 +37,7 @@
 
 (ert-deftest phpinspect-find-composer-json-files ()
   (let* ((fs (phpinspect-make-virtual-fs))
+         ;; FIXME: `autoloader' is not used?
          (autoloader (phpinspect-make-autoloader
                       :fs fs
                       :project-root-resolver (lambda () "/root")
@@ -57,12 +59,13 @@
 
     (let ((sorter (lambda (file1 file2) (string-lessp (cdr file1) (cdr 
file2)))))
 
-    (should (equal (sort '((vendor . "/root/vendor/apples/pears/composer.json")
-                           (vendor . 
"/root/vendor/runescape/client/composer.json")
-                           (local . "/root/composer.json"))
-                         sorter)
-                   (sort (phpinspect-find-composer-json-files fs "/root")
-                         sorter))))))
+      (should (equal (sort (copy-sequence
+                            '((vendor . 
"/root/vendor/apples/pears/composer.json")
+                              (vendor . 
"/root/vendor/runescape/client/composer.json")
+                              (local . "/root/composer.json")))
+                           sorter)
+                     (sort (phpinspect-find-composer-json-files fs "/root")
+                           sorter))))))
 
 (ert-deftest phpinspect-autoload-composer-json-iterator ()
   (let* ((fs (phpinspect-make-virtual-fs))
diff --git a/test/test-bmap.el b/test/test-bmap.el
index 613efaecfd..e0c17c7f52 100644
--- a/test/test-bmap.el
+++ b/test/test-bmap.el
@@ -1,3 +1,4 @@
+;; -*- lexical-binding: t; -*-
 
 (require 'phpinspect-bmap)
 
@@ -6,7 +7,6 @@
         (bmap2 (phpinspect-make-bmap))
         (bmap3 (phpinspect-make-bmap))
         (token '(:token))
-        (token1 '(:token1))
         (token2 '(:token2))
         (token3 '(:token3)))
 
@@ -69,13 +69,15 @@
     (phpinspect-bmap-register bmap 9  20 '(:node3))
     (phpinspect-bmap-register bmap 21  44 '(:node4))
 
-    (setq result (phpinspect-bmap-tokens-overlapping bmap 22))
-    (should (equal '((:node4) (:node2) (:node1)) (mapcar 
#'phpinspect-meta-token result)))))
+    (let ((result (phpinspect-bmap-tokens-overlapping bmap 22)))
+      (should (equal '((:node4) (:node2) (:node1))
+                     (mapcar #'phpinspect-meta-token result))))))
 
 (ert-deftest phpinspect-bmap-tokens-overlapping-overlayed ()
   (let ((bmap (phpinspect-make-bmap))
         (bmap2 (phpinspect-make-bmap))
-        (bmap3 (phpinspect-make-bmap)))
+        (bmap3 (phpinspect-make-bmap))
+        result)
     (phpinspect-bmap-register bmap 9 200 '(:token1))
     (phpinspect-bmap-register bmap 20 200 '(:token2))
     (phpinspect-bmap-register bmap 9 20 '(:token3))
diff --git a/test/test-buffer.el b/test/test-buffer.el
index 5d98719418..64442f9814 100644
--- a/test/test-buffer.el
+++ b/test/test-buffer.el
@@ -27,12 +27,11 @@
 (require 'phpinspect-parser)
 (require 'phpinspect-buffer)
 (require 'phpinspect-test-env
-         (concat (file-name-directory (or load-file-name buffer-file-name))
-                 "phpinspect-test-env.el"))
+         (expand-file-name "phpinspect-test-env.el"
+                           (file-name-directory (macroexp-file-name))))
 
 (ert-deftest phpinspect-buffer-region-lookups ()
-  (let* ((parsed)
-         (class))
+  (let* ((parsed))
     (with-temp-buffer
       (insert-file-contents (concat phpinspect-test-php-file-directory 
"/NamespacedClass.php"))
       (setq phpinspect-current-buffer
@@ -54,12 +53,11 @@
 (ert-deftest phpinspect-parse-buffer-no-current ()
   "Confirm that the parser is still functional with
 `phpinspect-current-buffer' unset."
-  (let*((buffer)
-        (parsed))
-    (with-temp-buffer
-      (should-not phpinspect-current-buffer)
-      (insert-file-contents (concat phpinspect-test-php-file-directory 
"/NamespacedClass.php"))
-      (setq parsed (phpinspect-parse-current-buffer)))
+  (let* ((parsed
+          (with-temp-buffer
+            (should-not phpinspect-current-buffer)
+            (insert-file-contents (expand-file-name "NamespacedClass.php" 
phpinspect-test-php-file-directory))
+            (phpinspect-parse-current-buffer))))
 
     (should (cdr parsed))))
 
diff --git a/test/test-edtrack.el b/test/test-edtrack.el
index b12ddc8360..adc2391578 100644
--- a/test/test-edtrack.el
+++ b/test/test-edtrack.el
@@ -106,8 +106,7 @@
     (should-not (phpinspect-taint-iterator-region-is-tainted-p iterator 30 
35))))
 
 (ert-deftest phpinspect-edtrack-taint-overlapping-edits ()
-  (let ((track (phpinspect-make-edtrack))
-        iterator)
+  (let ((track (phpinspect-make-edtrack)))
     (phpinspect-edtrack-register-edit track 10 20 5)
 
     (should (equal (list (cons 10 15)) (phpinspect-edtrack-taint-pool track)))
diff --git a/test/test-index.el b/test/test-index.el
index 232cc1c9ae..bd2c2cde2c 100644
--- a/test/test-index.el
+++ b/test/test-index.el
@@ -24,6 +24,10 @@
 ;;; Code:
 (require 'ert)
 (require 'phpinspect-index)
+(require 'phpinspect-parse-context)
+(require 'phpinspect-bmap)
+(require 'phpinspect-parser)
+(require 'phpinspect-test-env)
 
 (ert-deftest phpinspect-index-static-methods ()
   (let* ((class-tokens
@@ -92,8 +96,9 @@ return StaticThing::create(new 
ThingFactory())->makeThing((((new Potato())->anti
     (should (equal
              (mapcar #'phpinspect-intern-name
                      (sort
-                      '("Cheese" "Bacon" "Ham" "Bagel" "Monkey" "ExtendedThing"
-                        "StaticThing" "Thing" "ThingFactory" "Potato" 
"OtherThing")
+                      (copy-sequence
+                       '("Cheese" "Bacon" "Ham" "Bagel" "Monkey" 
"ExtendedThing"
+                         "StaticThing" "Thing" "ThingFactory" "Potato" 
"OtherThing"))
                       #'string<))
              (sort used-types (lambda (s1 s2) (string< (symbol-name s1) 
(symbol-name s2))))))))
 
@@ -172,7 +177,7 @@ return StaticThing::create(new 
ThingFactory())->makeThing((((new Potato())->anti
   (let* ((pctx (phpinspect-make-pctx :incremental t :bmap 
(phpinspect-make-bmap)))
          (tree))
     (with-temp-buffer
-      (insert-file-contents (concat phpinspect-test-php-file-directory 
"/IndexClass1.php"))
+      (insert-file-contents (expand-file-name "IndexClass1.php" 
phpinspect-test-php-file-directory))
       (setf (phpinspect-pctx-bmap pctx) (phpinspect-make-bmap))
       (phpinspect-with-parse-context pctx (setq tree 
(phpinspect-parse-current-buffer))))
     (let* ((index1 (phpinspect--index-tokens tree
diff --git a/test/test-parse-context.el b/test/test-parse-context.el
index a9d69c2384..4fffdc4e61 100644
--- a/test/test-parse-context.el
+++ b/test/test-parse-context.el
@@ -26,6 +26,7 @@
 (require 'ert)
 (require 'phpinspect-parse-context)
 (require 'phpinspect-meta)
+(require 'phpinspect-bmap)
 
 (ert-deftest phpinspect-pctx-cancel ()
   (let ((meta (phpinspect-make-meta nil 10 20 "    " 'token 'overlay nil))
diff --git a/test/test-parser.el b/test/test-parser.el
index a7b3660d67..198998419e 100644
--- a/test/test-parser.el
+++ b/test/test-parser.el
@@ -24,20 +24,17 @@
 ;;; Code:
 
 (require 'phpinspect-parser)
+(require 'phpinspect-index)
+(require 'phpinspect-test-env)
 
+;; FIXME: Duplicate in phpinspect-test-env.el!
 (defvar phpinspect-test-directory
-  (file-name-directory
-   (or load-file-name
-       buffer-file-name))
+  (file-name-directory (macroexp-file-name))
   "Directory that phpinspect tests reside in.")
 
 
 (defvar phpinspect-test-php-file-directory
-  (concat
-   (file-name-directory
-    (or load-file-name
-        buffer-file-name))
-   "/fixtures")
+  (expand-file-name "fixtures" phpinspect-test-directory)
   "Directory with syntax trees of example PHP files.")
 
 
diff --git a/test/test-pipeline.el b/test/test-pipeline.el
index f9c1ed04a3..d7285825c1 100644
--- a/test/test-pipeline.el
+++ b/test/test-pipeline.el
@@ -25,14 +25,15 @@
 
 (require 'phpinspect-pipeline)
 
+(defun phpinspect--correct-the-record (input)
+  (phpinspect-pipeline-emit
+   (format "It's not %s, but GNU/%s" input input)))
+
 (ert-deftest phpinspect-pipeline ()
-  (let (result error thread)
-    (defun correct-the-record (input)
-      (phpinspect-pipeline-emit
-       (format "It's not %s, but GNU/%s" input input)))
+  (let (result error)
 
     (phpinspect-pipeline (list "Linux" "Emacs")
-      :into correct-the-record
+      :into phpinspect--correct-the-record
       :async (lambda (res err)
                (setq result res
                      error err)))
@@ -44,13 +45,14 @@
                    result))
     (should-not error)))
 
+(defun phpinspect--aah-it-broke (input)
+  (signal 'it-brokey input))
+
 (ert-deftest phpinspect-pipeline-error ()
-  (defun aah-it-broke (input)
-    (signal 'it-brokey input))
 
   (let (result error)
     (phpinspect-pipeline (list "Holy smokey")
-      :into aah-it-broke
+      :into phpinspect--aah-it-broke
       :async (lambda (res err)
                (setq result res
                      error err)))
diff --git a/test/test-project.el b/test/test-project.el
index b421eebc7c..0b03df5eb2 100644
--- a/test/test-project.el
+++ b/test/test-project.el
@@ -35,11 +35,11 @@
 (ert-deftest phpinspect-project-watch-file-and-purge ()
   (let* ((root (make-temp-file "phpinspect-test" 'dir))
          (fs (phpinspect-make-fs))
-         (worker (phpinspect-make-worker))
+         (_worker (phpinspect-make-worker))
          (watch-file (concat root "/watch1"))
          (project (phpinspect--make-project :fs fs :root root)))
     (phpinspect-project-watch-file project watch-file
-                                    (lambda (&rest ignored)))
+                                   #'ignore)
 
     (phpinspect-project-purge project)
 
diff --git a/test/test-resolvecontext.el b/test/test-resolvecontext.el
index 894f684080..72888cd845 100644
--- a/test/test-resolvecontext.el
+++ b/test/test-resolvecontext.el
@@ -1,5 +1,8 @@
+;; -*- lexical-binding: t; -*-
 
 (require 'phpinspect-resolvecontext)
+(require 'phpinspect)
+(require 'phpinspect-test-env)
 
 (ert-deftest phinspect-get-resolvecontext ()
   (let* ((ctx (phpinspect-make-pctx :incremental t :bmap 
(phpinspect-make-bmap)))
@@ -29,7 +32,7 @@ class TestClass {
 
 (ert-deftest phpinspect-type-resolver-for-resolvecontext ()
   (with-temp-buffer
-    (insert-file-contents (concat phpinspect-test-php-file-directory 
"/IncompleteClass.php"))
+    (insert-file-contents (expand-file-name "IncompleteClass.php" 
phpinspect-test-php-file-directory))
     (let* ((bmap (phpinspect-parse-string-to-bmap (buffer-string)))
            (resolvecontext (phpinspect-get-resolvecontext bmap (point-max)))
            (type-resolver (phpinspect--make-type-resolver-for-resolvecontext
@@ -81,8 +84,8 @@ class TestClass {
 
 (ert-deftest 
phpinspect-type-resolver-for-resolvecontext-multiple-namespace-blocks ()
   (with-temp-buffer
-    (insert-file-contents (concat phpinspect-test-php-file-directory 
"/IncompleteClassMultipleNamespaces.php"))
-    (let* ((bmap (phpinspect-parse-string-to-bmap (buffer-string)))
+    (insert-file-contents (expand-file-name 
"IncompleteClassMultipleNamespaces.php" phpinspect-test-php-file-directory))
+    (let* ((_bmap (phpinspect-parse-string-to-bmap (buffer-string)))
            (resolvecontext (phpinspect--get-resolvecontext
                           (phpinspect-test-read-fixture-data
                            "IncompleteClassMultipleNamespaces")))
diff --git a/test/test-splayt.el b/test/test-splayt.el
index 07f37c6e96..04db40f6fa 100644
--- a/test/test-splayt.el
+++ b/test/test-splayt.el
@@ -71,7 +71,7 @@
     (should (string= "twelve" (phpinspect-splayt-find tree 12)))
     (should (string= "eleven" (phpinspect-splayt-find tree 11)))
 
-    (let ((expected (sort '("nine" "three" "eleven" "eight" "twelve" "four" 
"one") #'string-lessp))
+    (let ((expected (sort (copy-sequence '("nine" "three" "eleven" "eight" 
"twelve" "four" "one")) #'string-lessp))
           (result))
 
       (phpinspect-splayt-traverse (item tree)
@@ -91,7 +91,7 @@
     (phpinspect-splayt-insert tree 4 "four")
     (phpinspect-splayt-insert tree 1 "one")
 
-    (let ((expected (sort '("nine" "three" "eleven" "eight" "twelve" "four" 
"one") #'string-lessp))
+    (let ((expected (sort (copy-sequence '("nine" "three" "eleven" "eight" 
"twelve" "four" "one")) #'string-lessp))
           (result))
 
       (phpinspect-splayt-traverse (item tree)
@@ -161,7 +161,7 @@
     (phpinspect-splayt-insert tree 1 "one")
 
 
-    (should (equal (sort '("eight" "nine" "eleven" "twelve") #'string-lessp)
+    (should (equal (sort (copy-sequence '("eight" "nine" "eleven" "twelve")) 
#'string-lessp)
                    (sort (phpinspect-splayt-find-all-after tree 7) 
#'string-lessp)))))
 
 (ert-deftest phpinspect-splayt-to-list ()
diff --git a/test/test-toc.el b/test/test-toc.el
index 99d758290b..4843da3b99 100644
--- a/test/test-toc.el
+++ b/test/test-toc.el
@@ -2,6 +2,7 @@
 
 (require 'phpinspect-toc)
 (require 'phpinspect-splayt)
+(require 'phpinspect-meta)
 
 (ert-deftest phpinspect-make-toc ()
   (let ((tokens (phpinspect-make-splayt))
diff --git a/test/test-type.el b/test/test-type.el
index 47b212e544..d5933cb93a 100644
--- a/test/test-type.el
+++ b/test/test-type.el
@@ -23,6 +23,8 @@
 
 ;;; Code:
 
+(require 'phpinspect-type)
+
 (ert-deftest phpinspect--resolve-late-static-binding ()
   (let* ((sets '(("\\bool" . "\\bool")
                  ("\\static" . "\\AType")
diff --git a/test/test-util.el b/test/test-util.el
index c10e7bd360..72ce39f966 100644
--- a/test/test-util.el
+++ b/test/test-util.el
@@ -23,6 +23,8 @@
 
 ;;; Code:
 
+(require 'phpinspect-util)
+
 (ert-deftest phpinspect--pattern ()
   (let* ((a "a")
          (pattern1 (phpinspect--make-pattern :m `(,a) :m * :m "b"))
diff --git a/test/util/generate-test-data.el b/test/util/generate-test-data.el
index 2211fcac97..a181080ecc 100644
--- a/test/util/generate-test-data.el
+++ b/test/util/generate-test-data.el
@@ -3,12 +3,10 @@
 (require 'phpinspect-index)
 (require 'phpinspect-serialize)
 
-(let ((here (file-name-directory
-             (or load-file-name
-                 buffer-file-name)))
+(let ((here (file-name-directory (macroexp-file-name)))
       (print-length 1000)
       (print-level 1000))
-  (dolist (file (directory-files (concat here "/../fixtures" ) t "\\.php\\'"))
+  (dolist (file (directory-files (expand-file-name "../fixtures" here) t 
"\\.php\\'"))
     (with-temp-buffer
       (insert-file-contents-literally file)
       (let ((result (phpinspect-parse-current-buffer)))

reply via email to

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