From 644d13ff924a13b84e34dd143d1eda5e8b3a2288 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Mon, 8 May 2017 15:21:23 +0530 Subject: [PATCH] Emacs: Use 'recompile' instead of 'compile-here' --- .emacs.d/lisp/functions.el | 28 ------------------------ .emacs.d/lisp/main.el | 12 +++++------ .emacs.d/lisp/mode-cc.el | 2 +- .emacs.d/lisp/mode-latex.el | 4 +++- .emacs.d/lisp/mode-python.el | 30 ++++++++++---------------- .emacs.d/lisp/mode-sh.el | 4 ++-- .emacs.d/lisp/mode-tex.el | 41 ++++++++++++++++++------------------ 7 files changed, 44 insertions(+), 77 deletions(-) diff --git a/.emacs.d/lisp/functions.el b/.emacs.d/lisp/functions.el index 9580cf38..501468ad 100644 --- a/.emacs.d/lisp/functions.el +++ b/.emacs.d/lisp/functions.el @@ -21,34 +21,6 @@ sure it gets executed." standard-output (apply 'call-process program nil t nil args)))) -;; (defcustom compilation-after-hook nil -;; "List of hook functions run by `compile-custom'." -;; :type 'hook -;; :group 'compilation) - -(defcustom compilation-before-hook nil - "List of hook functions run by `compile-custom'. -You may want to set the `compile-command' with this hook. If you -do so, do not forget to set the LOCAL flag to t." - :type 'hook - :group 'compilation) - -(defvar compilation-time-before-hide-window nil - "Hide compilation window after the specified seconds. -If nil, do not hide.") - -(defun compile-here (&optional runhooks) - "Call `recompile' in the default directory. -If RUNHOOKS is non-nil (or with \\[universal-argument]), run hooks in -`compilation-before-hook', then `recompile'." - (interactive "P") - (when (or runhooks (string= compile-command "make -k ")) (run-hooks 'compilation-before-hook)) - (setq-default compilation-directory default-directory) - (recompile) - (when compilation-time-before-hide-window - (sit-for compilation-time-before-hide-window) - (delete-windows-on "*compilation*"))) - (defun count-occurences (regex string) "Return number of times regex occurs in string. If you want to operate on buffer, use `how-many' instead." diff --git a/.emacs.d/lisp/main.el b/.emacs.d/lisp/main.el index d1304b46..252ec690 100644 --- a/.emacs.d/lisp/main.el +++ b/.emacs.d/lisp/main.el @@ -216,13 +216,13 @@ (auto-fill-mode -1)))) ;; Compilation bindings and conveniences. -(require 'functions) ; for `compile-custom' (setq compilation-ask-about-save nil) -(autoload 'recompile "compile" nil t) -(define-key mickey-minor-mode-map (kbd "C-") 'compile) -(define-key mickey-minor-mode-map (kbd "") 'compile-here) -(define-key mickey-minor-mode-map (kbd "") 'previous-error) -(define-key mickey-minor-mode-map (kbd "") 'next-error) +;; Don't set these bindings in mickey as we might have to override them from +;; mode hooks. +(global-set-key (kbd "C-") 'compile) +(global-set-key (kbd "") 'recompile) +(global-set-key (kbd "") 'previous-error) +(global-set-key (kbd "") 'next-error) ;; Code browsing: make C-M-e jump to next function instead of the end of the current function. (define-key mickey-minor-mode-map (kbd "C-M-e") (lambda () (interactive) (beginning-of-defun -1))) diff --git a/.emacs.d/lisp/mode-cc.el b/.emacs.d/lisp/mode-cc.el index 0febabe0..daba698b 100644 --- a/.emacs.d/lisp/mode-cc.el +++ b/.emacs.d/lisp/mode-cc.el @@ -119,7 +119,7 @@ restored." mode-hook (lambda () (c-set-style "ambrevar") ;; We override existing values. - (add-hook 'compilation-before-hook 'cc-set-compiler nil t) + (cc-set-compiler) (local-set-key (kbd "") 'cc-clean) (local-set-key (kbd "M-.") 'semantic-ia-fast-jump) (local-set-key (kbd "C-c C-d") 'semantic-ia-show-summary) diff --git a/.emacs.d/lisp/mode-latex.el b/.emacs.d/lisp/mode-latex.el index 9c1c722f..1424817b 100644 --- a/.emacs.d/lisp/mode-latex.el +++ b/.emacs.d/lisp/mode-latex.el @@ -51,8 +51,10 @@ 'latex-mode-hook (lambda () (set (make-local-variable 'tex-extension-list) - '("aux" "bbl" "blg" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "maf" "mt" "mtc" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy")) + '("aux" "bbl" "blg" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "maf" "mt" "mtc" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy")) (set (make-local-variable 'tex-command) "pdflatex") + ;; Need to reset the compiler because we changed tex-command. + (tex-set-compiler) ;; For some unknown reasons, `skeleton-end-hook' is set to nil in tex-mode. (add-hook 'skeleton-end-hook 'skeleton-make-markers) (local-set-key (kbd "C-c m") 'latex-article) diff --git a/.emacs.d/lisp/mode-python.el b/.emacs.d/lisp/mode-python.el index 4d95f495..c262c6b9 100644 --- a/.emacs.d/lisp/mode-python.el +++ b/.emacs.d/lisp/mode-python.el @@ -1,29 +1,21 @@ ;; Python -(defun python-version () - "Returns \"python2\" or \"python3\" according to the shabang. -`python-shell-interpreter' is assumed by default." - (let ((firstline - (car - (split-string (buffer-substring-no-properties 1 (point-max)) "\n")))) - (if (not (string-match "^#!" firstline)) - "python" - (cond - ((string-match "python2" firstline) "python2") - ((string-match "python3" firstline) "python3") - (t python-shell-interpreter))))) - -(defun python-set-interpreter () - "Use compile to run python programs." - (interactive) - (set (make-local-variable 'compile-command) - (concat (python-version) " " (shell-quote-argument buffer-file-name)))) +(defun python-set-compiler () + "Returns the value of the shebang if any, `python-shell-interpreter' otherwise." + (let* ((firstline + (save-excursion (beginning-of-buffer) (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) + (interpreter + (if (not (string-match "^#!" firstline)) + python-shell-interpreter + (substring firstline 2)))) + (set (make-local-variable 'compile-command) + (concat interpreter " " (shell-quote-argument buffer-file-name))))) (add-hook-and-eval 'python-mode-hook (lambda () (set (make-local-variable 'compilation-scroll-output) t) - (add-hook 'compilation-before-hook 'python-set-interpreter nil t))) + (python-set-compiler))) ;; Doc lookup. Requires the python.info file to be installed. See ;; https://bitbucket.org/jonwaltman/pydoc-info/. diff --git a/.emacs.d/lisp/mode-sh.el b/.emacs.d/lisp/mode-sh.el index d46e5fe4..eb58a230 100644 --- a/.emacs.d/lisp/mode-sh.el +++ b/.emacs.d/lisp/mode-sh.el @@ -8,7 +8,7 @@ (setq-default sh-shell-file sh-shell-file) ;; (setq-default sh-shell 'sh) -(defun sh-set-interpreter () +(defun sh-set-compiler () "Set shell interpreter. Set `sh-shell', `sh-shell-file' and `compile-command' according to the following rules: - Look at shabang. @@ -67,7 +67,7 @@ The advantages of this function over the vanilla code are: (setq sh-indent-for-case-alt '+) (set (make-local-variable 'defun-prompt-regexp) (concat "^\\(function[ \t]\\|[[:alnum:]_]+[ \t]+()[ \t]+\\)")) - (sh-set-interpreter))) + (sh-set-compiler))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/.emacs.d/lisp/mode-tex.el b/.emacs.d/lisp/mode-tex.el index 30f81460..1be4719c 100644 --- a/.emacs.d/lisp/mode-tex.el +++ b/.emacs.d/lisp/mode-tex.el @@ -21,18 +21,19 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Custom -(defcustom masterfile nil - "The file that should be compiled. Useful for modular documents." - :safe 'stringp) +(defvar-local tex-masterfile nil + "The file that should be compiled. Useful for modular documents.") +(defvar-local tex-compilation-delay 2 + "Delay before hiding the compilation window.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variables -(defvar tex-extension-list nil +(defcustom tex-extension-list nil "List of known TeX exentsions. This list is used by `tex-clean' to purge all matching files.") -(defvar tex-index-command "makeindex" +(defcustom tex-index-command "makeindex" "The TeX index file generator.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -44,8 +45,7 @@ (hack-local-variables) (let* (;; Master file. (local-master - - (if masterfile masterfile (if buffer-file-name buffer-file-name (error "Buffer has no file name")))) + (if tex-masterfile tex-masterfile (if buffer-file-name buffer-file-name (error "Buffer has no file name")))) (dirname (file-name-directory local-master)) (basename (file-name-sans-extension (file-name-nondirectory local-master))) ;; Note: makeindex fails with absolute file names, we need relative names. @@ -54,9 +54,9 @@ (concat "cd " (if dirname (shell-quote-argument dirname) ".") " && " (when (executable-find tex-index-command) - (concat tex-index-command " " (shell-quote-argument (concat basename ".idx")) " ; ")) + (concat tex-index-command " " (shell-quote-argument (concat basename ".idx")) "; ")) (when (executable-find tex-bibtex-command) - (concat tex-bibtex-command " " (shell-quote-argument basename) " ; ")) + (concat tex-bibtex-command " " (shell-quote-argument basename) "; ")) tex-command " " tex-start-options " " tex-start-commands @@ -68,8 +68,8 @@ but there is no warranty." (interactive) (hack-local-variables) (let ((master (concat - (if masterfile - (file-name-sans-extension masterfile) + (if tex-masterfile + (file-name-sans-extension tex-masterfile) (file-name-sans-extension buffer-file-name)) "."))) (mapcar @@ -84,19 +84,19 @@ but there is no warranty." tex-extension-list)))) (defun tex-pdf-compress () - "Use `masterfile' variable as default value for `pdf-compress'." + "Use `tex-masterfile' variable as default value for `pdf-compress'." (interactive) (require 'tool-pdf) (hack-local-variables) - (let ((local-master (if masterfile masterfile buffer-file-name))) + (let ((local-master (if tex-masterfile tex-masterfile buffer-file-name))) (pdf-compress local-master))) (defun tex-pdf-view () - "Use `masterfile' variable as default value for `pdf-view'." + "Use `tex-masterfile' variable as default value for `pdf-view'." (interactive) (require 'tool-pdf) (hack-local-variables) - (let ((local-master (if masterfile masterfile buffer-file-name))) + (let ((local-master (if tex-masterfile tex-masterfile buffer-file-name))) (pdf-view local-master))) (defun tex-toggle-escape-char () @@ -113,10 +113,12 @@ This does not interfere with `subword-mode'." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TeX setup -(setq tex-start-options "-file-line-error-style -interaction=nonstopmode -synctex=1 ") +(setq-default tex-command "pdftex") +(setq tex-command "pdftex") +(setq-default tex-start-options "-file-line-error-style -interaction=nonstopmode -synctex=1") ;; Use the following variable to append file local commands without erasing ;; default options. -(setq tex-start-commands nil) +(setq-default tex-start-commands nil) (add-hook-and-eval 'tex-mode-hook @@ -129,13 +131,12 @@ This does not interfere with `subword-mode'." (local-unset-key key)) (set-face-attribute 'tex-verbatim nil :family "freemono") (set (make-local-variable 'compilation-scroll-output) t) - (set (make-local-variable 'compilation-time-before-hide-window) 2) (set (make-local-variable 'paragraph-start) " ") ;; (set (make-local-variable 'use-hard-newlines) t) (local-set-key (kbd "") 'tex-pdf-view) - (setq tex-command "pdftex") - (add-hook 'compilation-before-hook 'tex-set-compiler nil t))) + (local-set-key (kbd "") (lambda () (interactive) (progn (recompile) (sit-for tex-compilation-delay) (delete-windows-on "*compilation*")))) + (tex-set-compiler))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Skeletons