branch: externals/phpinspect commit f2ece03f2adac212ee8654941633e75219f4bb04 Author: Hugo Thunnissen <de...@hugot.nl> Commit: Hugo Thunnissen <de...@hugot.nl>
Add factilities to filter logs from different modules --- phpinspect-bmap.el | 4 ++- phpinspect-buffer.el | 9 ++++--- phpinspect-edtrack.el | 5 ++++ phpinspect-util.el | 68 +++++++++++++++++++++++++++++++++++++++------------ 4 files changed, 67 insertions(+), 19 deletions(-) diff --git a/phpinspect-bmap.el b/phpinspect-bmap.el index 5ba1d3ed2c..0fded42705 100644 --- a/phpinspect-bmap.el +++ b/phpinspect-bmap.el @@ -33,7 +33,9 @@ (defvar phpinspect-parse-context nil "dummy for compilation") - (declare-function phpinspect-pctx-register-changeset "phpinspect-parse-context" (pctx changeset))) + (declare-function phpinspect-pctx-register-changeset "phpinspect-parse-context" (pctx changeset)) + + (phpinspect--declare-log-group 'bmap)) (cl-defstruct (phpinspect-bmap (:constructor phpinspect-make-bmap)) (starts (make-hash-table :test #'eql diff --git a/phpinspect-buffer.el b/phpinspect-buffer.el index 51d902c238..357381d938 100644 --- a/phpinspect-buffer.el +++ b/phpinspect-buffer.el @@ -117,12 +117,15 @@ use." (phpinspect-bmap-make-location-resolver (phpinspect-buffer-map buffer))) token)))) +(cl-defmethod phpinspect-buffer-root-meta ((buffer phpinspect-buffer)) + (phpinspect-bmap-root-meta (phpinspect-buffer-map buffer))) + (defun phpinspect-display-buffer-tree () (interactive) (when phpinspect-current-buffer (let ((buffer phpinspect-current-buffer)) - (pop-to-buffer (generate-new-buffer "phpinspect-buffer-tree")) - (insert (pp-to-string (phpinspect-buffer-tree buffer))) - (read-only-mode)))) + (pop-to-buffer (generate-new-buffer "phpinspect-buffer-tree")) + (insert (pp-to-string (phpinspect-buffer-parse buffer 'no-interrupt))) + (read-only-mode)))) (provide 'phpinspect-buffer) diff --git a/phpinspect-edtrack.el b/phpinspect-edtrack.el index 78fc7224a9..73e56b42a6 100644 --- a/phpinspect-edtrack.el +++ b/phpinspect-edtrack.el @@ -23,6 +23,11 @@ ;;; Code: +(require 'phpinspect-util) + +(eval-when-compile + (phpinspect--declare-log-group 'edtrack)) + (cl-defstruct (phpinspect-edtrack (:constructor phpinspect-make-edtrack)) (edits nil :type list) diff --git a/phpinspect-util.el b/phpinspect-util.el index 0eb73661b8..be8d14759a 100644 --- a/phpinspect-util.el +++ b/phpinspect-util.el @@ -30,6 +30,59 @@ PHP. Used to optimize string comparison.") (defvar phpinspect--debug nil "Enable debug logs for phpinspect by setting this variable to true") +(defun phpinspect-toggle-logging () + (interactive) + (if (setq phpinspect--debug (not phpinspect--debug)) + (message "Enabled phpinspect logging.") + (message "Disabled phpinspect logging."))) + +(defvar phpinspect-log-groups nil) +(defvar phpinspect-enabled-log-groups nil) + +(defvar-local phpinspect--current-log-group nil) + +(define-inline phpinspect--declare-log-group (group) + (unless (and (inline-const-p group) (symbolp (inline-const-val group))) + (inline-error "Log group name should be a symbol")) + + (inline-quote + (progn + (add-to-list 'phpinspect-log-groups (cons (or load-file-name buffer-file-name) ,group) nil #'equal)))) + +(defun phpinspect-log-group-enabled-p (group) + (seq-find (lambda (cons) + (eq group (cdr cons))) + phpinspect-enabled-log-groups)) + +(phpinspect--declare-log-group 'bam) + +(define-inline phpinspect--log (&rest args) + (let ((log-group (alist-get (or load-file-name buffer-file-name) phpinspect-log-groups nil nil #'string=))) + (push 'list args) + (inline-quote + (when (and phpinspect--debug + (or (not phpinspect-enabled-log-groups) + ,(when log-group + (inline-quote + (member (quote ,log-group) phpinspect-enabled-log-groups))))) + (with-current-buffer (get-buffer-create "**phpinspect-logs**") + (unless window-point-insertion-type + (set (make-local-variable 'window-point-insertion-type) t)) + (goto-char (buffer-end 1)) + (insert (concat "[" (format-time-string "%H:%M:%S") "]: " + ,(if log-group (concat "(" (symbol-name log-group) ") ") "") + (apply #'format ,args) "\n"))))))) + +(defun phpinspect-filter-logs (group-name) + (interactive (list (completing-read "Log group: " + (mapcar (lambda (g) (symbol-name (cdr g))) + phpinspect-log-groups) nil t))) + (add-to-list 'phpinspect-enabled-log-groups (intern group-name))) + +(defun phpinspect-unfilter-logs () + (interactive) + (setq phpinspect-enabled-log-groups nil)) + (defsubst phpinspect-intern-name (name) (intern name phpinspect-name-obarray)) @@ -46,21 +99,6 @@ PHP. Used to optimize string comparison.") (push item new-plist)) (nreverse new-plist))) -(defun phpinspect-toggle-logging () - (interactive) - (if (setq phpinspect--debug (not phpinspect--debug)) - (message "Enabled phpinspect logging.") - (message "Disabled phpinspect logging."))) - -(defsubst phpinspect--log (&rest args) - (when phpinspect--debug - (with-current-buffer (get-buffer-create "**phpinspect-logs**") - (unless window-point-insertion-type - (set (make-local-variable 'window-point-insertion-type) t)) - (goto-char (buffer-end 1)) - (insert (concat "[" (format-time-string "%H:%M:%S") "]: " - (apply #'format args) "\n"))))) - (cl-defstruct (phpinspect--pattern (:constructor phpinspect--make-pattern-generated)) "An object that can be used to match lists to a given