From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Detect latexmk is running on currently buffer. Date: Tue, 12 Oct 2021 15:54:49 +0800 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36282"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 12 10:13:53 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1maCv3-0009GN-4Z for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 12 Oct 2021 10:13:53 +0200 Original-Received: from localhost ([::1]:49212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1maCv2-0007uu-58 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 12 Oct 2021 04:13:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maCcr-00006l-Ne for help-gnu-emacs@gnu.org; Tue, 12 Oct 2021 03:55:05 -0400 Original-Received: from mail-ua1-x934.google.com ([2607:f8b0:4864:20::934]:36723) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maCcn-0006F0-IY for help-gnu-emacs@gnu.org; Tue, 12 Oct 2021 03:55:04 -0400 Original-Received: by mail-ua1-x934.google.com with SMTP id g13so16440785uaj.3 for ; Tue, 12 Oct 2021 00:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=qml57xN9xy8F613jT9nRBg76pmDYRNAvNYagEWOgiWM=; b=kpGc7dFxsOku2TXNu2F27KflJDG0cQzdsC4+6SqNXmCzvRFue7guzv1GwT4bf8YZMD E+jVa/kFj2nWPAkZEUkAxsaTlv/qBq8lwYVUuOsG/TW75Oc2cD4jHZB2cPU7lzHwthfn X9JoGK2FrAgPLw85jXRS7i1ZzBQ43D6XJrdY1dU1JW9AF9yp83ysXsd6eEoZab3x2p97 IpkNzh8U763PFzGf170CUnjNXpXLtYb4+yM6N9+C7oOkfOpTLv9onJTm2ySL0uR+OWUm 64rRr/bfZ7wOYNyavJLKwF4k9HbpPvPQY/dnRv2dQZ+1I3DfJTl+9rybuzLlNwFylcrk 4Sog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=qml57xN9xy8F613jT9nRBg76pmDYRNAvNYagEWOgiWM=; b=qDq/y5Vkgw85Dj6z7lpj1SkYUAewWZau3g4mOoUlWf+1gHBhbMi/guZMWoV7BEBkup d56k7fp+4ESYRXeDWIUtN4tmprGYWToyCkW8clI4HjDbOgZtgIu08hVdz6OC+JoZryOD e/Qxw4vwdXtboA0Uym+HH+Nzv2UYNyWEdakaAO40C6z2Yo2qfpa8nIhxVXeaoe4C9T/7 KLwKIzvsBGkqCpt033vDv+XTp03nz2YbBUHHdGlahAJGufHp5ivja1s0OiWQYsoUzXpk uAedPWYtdR2ISYNy917vqFYaj5McKeKFua+vXuYfamRlFBBcxvOLleegc/d+x7gPhUxQ KXUg== X-Gm-Message-State: AOAM531h61xiiSNLOribLsXNDc0WU/HtGpITUu94bS//CKLw9ktAnxj9 4rVHq/ZGZL2vMml6njZacJYKlPLRU/kuYcUo5fpLHNxt0J3/UxZx X-Google-Smtp-Source: ABdhPJwr9Nd8gO9POreTA/IlX7ApTDNW8+2++v91ZXBHcofp8C1mL4gYcohz0RvZF08WHoaxZNvModJndXEHx1nrCxQ= X-Received: by 2002:a67:c29d:: with SMTP id k29mr26567427vsj.51.1634025300166; Tue, 12 Oct 2021 00:55:00 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::934; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x934.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133745 Archived-At: Currently, I'm using the following configuration to automate the LaTeX workflow in Emacs with AUCTeX: ```emacs-lisp ;; Automatically revert a buffer when the corresponding file on disk is updated. (global-auto-revert-mode 1) (setq auto-revert-use-notify nil) ;; Automatically save the buffer to disk periodically. (use-package real-auto-save :hook ((TeX-mode python-mode) . real-auto-save-mode) :config (setq real-auto-save-interval 5) ;; in seconds ) ;; After the buffer is changed and saved to disk, run latexmk on the ;; corresponding file immediately. ;;See ~/.latexmkrc for correspoding configuration (use-package smart-compile :init (declare-function smart-compile-string "smart-compile") (defun run-latexmk () (when (string-match ".tex$" (buffer-file-name)) (let ((buf (get-buffer "*Background TeX proccess*"))) (if (bufferp buf) (kill-buffer buf))) ;; flush previous log (start-process-shell-command "Background TeX" "*Background TeX proccess*" ;; use an external application as the previewer ;;(smart-compile-string "latexmk -pv %f") ;; use pdf-tools (smart-compile-string "latexmk %f") ))) (define-minor-mode AutoTeX-mode "Mode for compiling latex sources and creating PDFs after saving." :global nil :lighter " Auto" (if AutoTeX-mode (add-hook 'after-save-hook 'run-latexmk t t) (remove-hook 'after-save-hook 'run-latexmk t))) :hook (LaTeX-mode . (lambda () (AutoTeX-mode 1))) ) ``` Though the above method works, I meet a problem when the project LaTeX files are large to some extent. To be more specific, when the project is large to a certain extent, the compilation time of latexmk will be relatively long, which may lead to the following race condition: When the previous latexmk process has not ended, the subsequent latexmk process is launched again. Any hints for fixing this problem? Regards -- Assoc. Prof. Hongyi Zhao Theory and Simulation of Materials Hebei Vocational University of Technology and Engineering No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province