1

I have customized tabbar to have a custom face for tabbar-selected-modified. The customizations work nicely for displaying the "modified" status of a buffer, and reverts to the default face when the buffer is saved.

I am now trying to extend after-save-hook to automatically compile LaTeX files on save. This also works correctly. But the problem is that the tabbar status (which was "modified" before I saved the buffer) for the buffer does not change back to the default (i.e., the buffer is saved) face.

Here is the code snippet that can be used to reproduce the problem.

(require 'package)
(setq package-user-dir (expand-file-name "~/.emacs.d/elpa/")
      package-enable-at-startup nil)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(eval-when-compile
  (require 'use-package))

(use-package tabbar
  :ensure t
  :preface
  (defun tabbar-modification-state-change ()
    (tabbar-set-template tabbar-current-tabset nil)
    (tabbar-display-update))

  (defun tabbar-on-buffer-modification ()
    (set-buffer-modified-p t)
    (tabbar-modification-state-change))
  :init (tabbar-mode 1)
  :config
  (add-hook 'after-save-hook #'tabbar-modification-state-change)
  (add-hook 'after-revert-hook #'tabbar-modification-state-change)
  (add-hook 'first-change-hook #'tabbar-on-buffer-modification)

  (set-face-attribute 'tabbar-selected-modified nil
                      :background "#f2f2f6"
                      :foreground "dark green"
                      :box '(:line-width 1 :color "black" :style sunken)
                      :height 1.3
                      :bold t
                      :underline nil))

(use-package tex-site ; Initialize auctex
  :ensure auctex
  :mode ("\\.tex\\'" . LaTeX-mode))

(use-package tex-buf ; Requires tex and latex
  :config
  (setq TeX-auto-save t ; Enable parse on save, stores parsed information in an "auto" directory
        TeX-save-query nil)
  (setq-default TeX-master nil))

(use-package tex-mode
  :init (setq latex-run-command "latexmk"))

(use-package auctex-latexmk
  :ensure t
  :config
  (auctex-latexmk-setup)
  (add-hook 'LaTeX-mode-hook
            (lambda ()
              (setq TeX-command-default "LaTeXMk"))))

(add-hook 'after-save-hook
          (lambda ()
            (when (string= major-mode "latex-mode")
              (TeX-command-menu "LaTeXMk"))))

To reproduce the problem, start with emacs -Q, evaluate the snippet, then open a LaTeX file and modify the buffer. You will notice that the tabbar face will change. Then, save the buffer. This will also trigger LaTeX compilation (with latexmk in this example). So far so good. But the problem is that the tabbar face does not revert back to the default (i.e., saved) face/state.

I have tried calling tabbar-modification-state-change in after-save-hook, but that does not solve the problem.

  • Check the modified status of the buffer after run your AUCTeX gizmo -- (buffer-modified-p) -- perhaps the buffer has been modified slightly by said AUCTeX gizmo -- e.g., with a text-property or something that doesn't look obvious. – lawlist Aug 15 '16 at 1:39
  • How do I check that? Should I evaluate (buffer-modified-p FILE) in *scratch*? This is what I did: (add-hook 'after-save-hook (lambda () (when (string= major-mode "latex-mode") (TeX-command-menu "LaTeXMk") (if (buffer-modified-p) (message "buffer is modified") (message "buffer is not modified"))))) It prints "buffer is modified." But I don't think that is correct, since the tabbar face gets updated to indicate a saved buffer when I reload the file. – Swarnendu Biswas Aug 15 '16 at 2:08
  • Depending upon how quickly the background process is running, your code may work. Otherwise, you may need to attach your test to the sentinel exit code -- I'm not familiar with all the stuff that AUCTeX does and when it does each thing-a-majig. The easiest way to test is just save the buffer, let your AUCTeX gizmo do its thing and then in the same buffer that contains the supposedly wrong tabbar indicator, type M-x eval-expression RET (buffer-modified-p) RET and see if it returns nil. If it does, then we move on to PLAN B (whatever that may be). – lawlist Aug 15 '16 at 2:15
  • The optional argument to buffer-modified-p is BUFFER-OR-NAME, so you could also evaluate from *scratch* using (buffer-modified-p (get-buffer BUFFER-OR-NAME)) The easiest is just to use the buffer-name -- FILE (all by itself), on the other hand, would not work. But there are other functions to obtain the buffer or buffer-name from the file . . . but that's beyond the scope of what we need to do. – lawlist Aug 15 '16 at 2:17
  • Thanks for your suggestions. I evaluated (buffer-modified-p) and it returns nil. So the issue should be in redrawing the tabbars properly after the after-save-hook is run. Note that the tabbar indicators are properly updated after a save if I do not have this LaTeX hook enabled. – Swarnendu Biswas Aug 15 '16 at 2:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.