[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex-cont-latexmk c6d624934e 061/100: some simplifica
From: |
ELPA Syncer |
Subject: |
[elpa] externals/auctex-cont-latexmk c6d624934e 061/100: some simplifications, clean-up |
Date: |
Thu, 6 Jun 2024 03:57:56 -0400 (EDT) |
branch: externals/auctex-cont-latexmk
commit c6d624934e33e31ee66356d20f4824b566ab0805
Author: Paul Nelson <ultrono@gmail.com>
Commit: Paul Nelson <ultrono@gmail.com>
some simplifications, clean-up
---
czm-tex-compile.el | 178 ++++++++++++++++++++++-------------------------------
1 file changed, 74 insertions(+), 104 deletions(-)
diff --git a/czm-tex-compile.el b/czm-tex-compile.el
index 86cd1ae768..68fac26010 100644
--- a/czm-tex-compile.el
+++ b/czm-tex-compile.el
@@ -59,62 +59,58 @@
(defvar czm-tex-compile--timer nil
"Timer for reporting changes to the log file.")
-(defconst czm-tex-compile--watching-str
- "=== Watching for updated files. Use ctrl/C to stop ..."
- "String indicating that latexmk is watching for updated files.")
-
-(defcustom czm-tex-compile-ignored-warnings
- '("Package hyperref Warning: Token not allowed in a PDF string")
- "List of warnings to ignore when parsing LaTeX log files."
- :type '(repeat string))
-
-(defcustom czm-tex-compile-report-hbox-errors nil
- "Non-nil means report hbox errors via flymake."
- :type 'boolean
- :group 'czm-tex-compile)
-
(defcustom czm-tex-compile-report-multiple-labels t
"Non-nil means report multiple label errors via flymake."
:type 'boolean
:group 'czm-tex-compile)
-(defun czm-tex-compile--process-multiply-defined-warning (message)
- "Get position of multiply defined MESSAGE labels."
- (let ((label (progn
- (string-match "`\\(.*\\)'" message)
- (match-string 1 message))))
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-min))
- (when (re-search-forward (concat "\\\\label{" label "}")
- nil t)
- (cons (line-beginning-position)
- (line-end-position)))))))
-
-(defun czm-tex-compile--process-regular-error (context line)
- "Get position of error and handle CONTEXT and LINE.
-Return a cons cell (BEG . END) indicating where the error happens, or
-nil if the error is not found."
- (when-let* ((prefix (with-temp-buffer
- (insert context)
- (goto-char (point-min))
- (when (re-search-forward "\nl\\.\\([0-9]+\\) " nil t)
- (buffer-substring-no-properties
- (point) (line-end-position)))))
- (pos
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-min))
- (forward-line (1- line))
- (let ((truncated-prefix
- (substring prefix (max 0 (- (length prefix) 3))))
- (line-end (line-end-position))
- (bol (point)))
- (or (search-forward truncated-prefix line-end t)
- bol))))))
- (cons pos (1+ pos))))
+(defun czm-tex-compile-process-item (type file line message offset context
search-string
+ _line-end bad-box _error-point
ignore)
+ "Process an error or warning for the current TeX document.
+The arguments are as in in `TeX-error-list'. Return either nil or a
+triple (ERROR-P DESCRIPTION (BEG . END)), where ERROR-P is non-nil if
+the error is an error rather than a warning, and the other elements of
+the triple describe the error or warning."
+ (and
+ (not ignore)
+ (stringp file)
+ (or (not bad-box) TeX-debug-bad-boxes)
+ (when-let
+ ((region
+ (save-restriction
+ (widen)
+ (cond
+ ((file-equal-p file (buffer-file-name))
+ (when line
+ (if (eq type 'error)
+ (save-excursion
+ (goto-char (point-min))
+ (forward-line (+ line offset -1))
+ (unless (string= search-string " ")
+ (search-forward search-string nil t)
+ (cons (point) (1+ (point)))))
+ (flymake-diag-region (current-buffer) (+ line offset)))))
+ ((file-equal-p file (TeX-master-file "aux"))
+ (and czm-tex-compile-report-multiple-labels
+ (string-match-p "multiply defined" message)
+ (not (eq type 'error))
+ (let* ((label (progn
+ (string-match "`\\(.*\\)'" message)
+ (match-string 1 message)))
+ (label-re
+ (concat "\\\\label\\(?:\\[[^]]+\\]\\)?{"
+ (regexp-quote label) "}")))
+ (save-excursion
+ (goto-char (point-min))
+ (when (re-search-forward label-re nil t)
+ ;; Return the full line so the diagnostic is
+ ;; not covered by preview overlays when
+ ;; \\label appears after \\begin{equation}.
+ (cons (line-beginning-position)
+ (line-end-position)))))))))))
+ (list (eq type 'error)
+ (replace-regexp-in-string "\n" "" message)
+ region))))
(defun czm-tex-compile--error-list (log-file)
"Retrieve parsed TeX error list from LOG-FILE."
@@ -133,46 +129,9 @@ Returns a list of triples (ERROR-P DESCRIPTION REGION),
where
ERROR-P is non-nil if the error is an error rather than a
warning, DESCRIPTION is what you'd expect, and REGION is a cons
cell (BEG . END) indicating where the error happens."
- (let* ((error-list (czm-tex-compile--error-list (TeX-master-file "log")))
- (processed-list
- (mapcar
- (lambda (item)
- (let ((error-p (eq (nth 0 item) 'error))
- (file (nth 1 item))
- (line (nth 2 item))
- (message (nth 3 item))
- (context (nth 5 item))
- (_search-string (nth 6 item))
- (is-bad-box (nth 8 item)))
- (when-let
- ((region
- (cond
- ((file-equal-p file (buffer-file-name))
- (and
- line
- (not (cl-some (lambda (ignored)
- (string-match-p ignored message))
- czm-tex-compile-ignored-warnings))
- (stringp file)
- (or (not is-bad-box)
- czm-tex-compile-report-hbox-errors)
- (if error-p
- (czm-tex-compile--process-regular-error context
line)
- (flymake-diag-region (current-buffer) line))))
- ((file-equal-p file (TeX-master-file "aux"))
- (and czm-tex-compile-report-multiple-labels
- (string-match-p "multiply defined" message)
- (not error-p)
- (czm-tex-compile--process-multiply-defined-warning
message))))))
- (list error-p
- (replace-regexp-in-string "\n" "" message)
- region))))
- error-list)))
- (delq nil processed-list)))
-
-(defun czm-tex-compile--compilation-command ()
- "Return the command used to compile the current LaTeX document."
- (format "%s %s" czm-tex-compile-command (TeX-master-file "tex")))
+ (delq nil (mapcar (lambda (item)
+ (apply #'czm-tex-compile-process-item item))
+ (czm-tex-compile--error-list (TeX-master-file "log")))))
(defun czm-tex-compile--compilation-buffer-name ()
"Return the name of the buffer used for LaTeX compilation."
@@ -183,6 +142,10 @@ cell (BEG . END) indicating where the error happens."
"Return the buffer used for LaTeX compilation."
(get-buffer (czm-tex-compile--compilation-buffer-name)))
+(defconst czm-tex-compile--watching-str
+ "=== Watching for updated files. Use ctrl/C to stop ..."
+ "String indicating that latexmk is watching for updated files.")
+
(defun czm-tex-compile--fresh-p ()
"Return non-nil if logged errors should apply to current buffer.
This is the case if the current buffer is not modified, the
@@ -236,19 +199,23 @@ e`czm-tex-compile--timer' to report diagnostics."
(let ((buf (current-buffer))
(comp-buf (czm-tex-compile--compilation-buffer))
done)
- (with-current-buffer comp-buf
- (setq czm-tex-compile--subscribed-buffers
- (cl-remove buf czm-tex-compile--subscribed-buffers))
- (when (null czm-tex-compile--subscribed-buffers)
- (setq done t)))
- (when done
- (let ((process (get-buffer-process comp-buf)))
- (when (process-live-p process)
- (interrupt-process process)
- (sit-for 0.1)
- (delete-process process))
- (kill-buffer comp-buf)))
- (setq czm-tex-compile--timer-enabled nil)))
+ (when comp-buf
+ (with-current-buffer comp-buf
+ (setq czm-tex-compile--subscribed-buffers
+ (cl-remove buf czm-tex-compile--subscribed-buffers))
+ (when (null czm-tex-compile--subscribed-buffers)
+ (setq done t)))
+ (when done
+ (let ((process (get-buffer-process comp-buf)))
+ (when (process-live-p process)
+ (interrupt-process process)
+ (sit-for 0.1)
+ (delete-process process))
+ (kill-buffer comp-buf))))))
+
+(defun czm-tex-compile--compilation-command ()
+ "Return the command used to compile the current LaTeX document."
+ (format "%s %s" czm-tex-compile-command (TeX-master-file "tex")))
;;;###autoload
(define-minor-mode czm-tex-compile-mode
@@ -278,6 +245,9 @@ e`czm-tex-compile--timer' to report diagnostics."
(setq czm-tex-compile--timer-enabled t))
(t
(czm-tex-compile--unsubscribe)
+ (remove-hook 'kill-buffer-hook 'czm-tex-compile--unsubscribe t)
+ (remove-hook 'flymake-diagnostic-functions #'czm-tex-compile-flymake t)
+ (setq czm-tex-compile--timer-enabled nil)
(when czm-tex-compile--report-fn
(setq czm-tex-compile--report-fn nil)))))
- [elpa] externals/auctex-cont-latexmk b5bd4c5257 024/100: indentation, (continued)
- [elpa] externals/auctex-cont-latexmk b5bd4c5257 024/100: indentation, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk e20b97607e 026/100: got it in OK shape, still quite rough tho, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 1384905db7 050/100: rearrange, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 7c7fcc15a9 053/100: mild factoring, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk b082dacb78 054/100: some good clean-up, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 62c2eb652a 031/100: print entire warning message (not every warning is a LaTeX warning), ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 5473521164 036/100: tweak readme, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 6cbd9d1493 067/100: respect TeX-output-dir, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 8333451e17 028/100: re-implement main logic using TeX-parse-all-errors, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 1aee5cc114 049/100: add "ignored" user option, started rearranging, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk c6d624934e 061/100: some simplifications, clean-up,
ELPA Syncer <=
- [elpa] externals/auctex-cont-latexmk ae9171666e 063/100: tidy, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 993c2e62fe 068/100: adapt TeX-format-filter to format log more robustly, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk a9d825f79c 069/100: attempt to make compilation command OS-compatible, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 826cf967f4 070/100: clarify commentary, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk d0fe19c0de 079/100: Make tex-continuous-mode independent of flymake, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk cdef4a9839 081/100: Remove t from flymake-diagnostic-functions, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk 832496d454 088/100: Support indirect buffers, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk c3ff2df047 030/100: restrict errors to those associated to some file, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk c2069da6b9 035/100: reduce "sit-for" time, ELPA Syncer, 2024/06/06
- [elpa] externals/auctex-cont-latexmk d377100af3 056/100: cleaning up, hopefully not ruining everything, ELPA Syncer, 2024/06/06