Emacs: compile--hook and dynamic compile-command for every mode
parent
36af4a2e10
commit
a3e3cd1d2f
|
@ -241,16 +241,39 @@
|
||||||
(speedbar-toggle-updates)))
|
(speedbar-toggle-updates)))
|
||||||
|
|
||||||
;; Compilation bindings and conveniences.
|
;; Compilation bindings and conveniences.
|
||||||
(setq compilation-hide-window nil)
|
(defvar compilation-time-before-hide-window nil
|
||||||
(define-key my-keys-minor-mode-map (kbd "<f10>")
|
"Hide compilation window after the specified seconds.
|
||||||
(lambda () (interactive)
|
If nil, do not hide.")
|
||||||
(save-buffer)
|
(defcustom compilation-before-hook nil
|
||||||
(compile compile-command)
|
"List of hook functions run by `compile-custom'."
|
||||||
(when compilation-hide-window
|
:type 'hook
|
||||||
(sit-for 2)
|
:group 'compilation)
|
||||||
(delete-windows-on "*compilation*"))))
|
(defcustom compilation-after-hook nil
|
||||||
|
"List of hook functions run by `compile-custom'."
|
||||||
|
:type 'hook
|
||||||
|
:group 'compilation)
|
||||||
|
|
||||||
|
(setq compilation-ask-about-save nil)
|
||||||
|
(autoload 'recompile "compile" nil t)
|
||||||
|
|
||||||
|
(define-key my-keys-minor-mode-map (kbd "<f10>") 'compile-custom)
|
||||||
(define-key my-keys-minor-mode-map (kbd "<f11>") 'previous-error)
|
(define-key my-keys-minor-mode-map (kbd "<f11>") 'previous-error)
|
||||||
(define-key my-keys-minor-mode-map (kbd "<f12>") 'next-error)
|
(define-key my-keys-minor-mode-map (kbd "<f12>") 'next-error)
|
||||||
|
|
||||||
|
(defun compile-custom ()
|
||||||
|
"Run hooks in `compilation-before-hook', then `recompile', then `compilation-after-hook'."
|
||||||
|
(interactive)
|
||||||
|
(run-hooks 'compilation-before-hook)
|
||||||
|
(recompile)
|
||||||
|
(run-hooks 'compilation-after-hook))
|
||||||
|
|
||||||
|
(add-hook
|
||||||
|
'compilation-after-hook
|
||||||
|
(lambda ()
|
||||||
|
(when compilation-time-before-hide-window
|
||||||
|
(sit-for compilation-time-before-hide-window)
|
||||||
|
(delete-windows-on "*compilation*"))))
|
||||||
|
|
||||||
;; Code browsing: make C-M-e jump to next function instead of the end of the current function.
|
;; Code browsing: make C-M-e jump to next function instead of the end of the current function.
|
||||||
(define-key my-keys-minor-mode-map (kbd "C-M-e") (lambda () (interactive) (beginning-of-defun -1)))
|
(define-key my-keys-minor-mode-map (kbd "C-M-e") (lambda () (interactive) (beginning-of-defun -1)))
|
||||||
|
|
||||||
|
|
|
@ -18,22 +18,23 @@
|
||||||
The Makefile is looked up in parent folders. If no Makefile is
|
The Makefile is looked up in parent folders. If no Makefile is
|
||||||
found, then a configurable command line is provided.\n
|
found, then a configurable command line is provided.\n
|
||||||
Requires `get-closest-pathname'."
|
Requires `get-closest-pathname'."
|
||||||
(require 'functions)
|
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(require 'functions)
|
||||||
|
(hack-local-variables)
|
||||||
(let ((makefile (get-closest-pathname)))
|
(let ((makefile (get-closest-pathname)))
|
||||||
(if makefile
|
(if makefile
|
||||||
(set (make-local-variable 'compile-command) (format "make -k -f %s" makefile))
|
(set (make-local-variable 'compile-command) (format "make -k -f %s" makefile))
|
||||||
(set (make-local-variable 'compile-command)
|
(set (make-local-variable 'compile-command)
|
||||||
(let
|
(let
|
||||||
((is-cpp (eq major-mode 'c++-mode))
|
((cppp (eq major-mode 'c++-mode))
|
||||||
(file (file-name-nondirectory buffer-file-name)))
|
(file (file-name-nondirectory buffer-file-name)))
|
||||||
(format "%s %s -o %s %s %s %s"
|
(format "%s %s -o %s %s %s %s"
|
||||||
(if is-cpp
|
(if cppp
|
||||||
(or (getenv "CXX") "g++")
|
(or (getenv "CXX") "g++")
|
||||||
(or (getenv "CC") "gcc"))
|
(or (getenv "CC") "gcc"))
|
||||||
file
|
file
|
||||||
(file-name-sans-extension file)
|
(file-name-sans-extension file)
|
||||||
(if is-cpp
|
(if cppp
|
||||||
(or (getenv "CPPFLAGS") "-Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0")
|
(or (getenv "CPPFLAGS") "-Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0")
|
||||||
(or (getenv "CFLAGS") "-ansi -pedantic -std=c99 -Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0"))
|
(or (getenv "CFLAGS") "-ansi -pedantic -std=c99 -Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0"))
|
||||||
(or (getenv "LDFLAGS") cc-ldflags)
|
(or (getenv "LDFLAGS") cc-ldflags)
|
||||||
|
@ -79,7 +80,7 @@ restored."
|
||||||
mode-hook
|
mode-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(c-set-style "peter")
|
(c-set-style "peter")
|
||||||
(cc-set-compiler)
|
(add-hook 'compilation-before-hook 'cc-set-compiler)
|
||||||
(local-set-key (kbd "<f9>") 'cc-clean)
|
(local-set-key (kbd "<f9>") 'cc-clean)
|
||||||
(local-set-key (kbd "M-TAB") 'semantic-complete-analyze-inline)
|
(local-set-key (kbd "M-TAB") 'semantic-complete-analyze-inline)
|
||||||
(local-set-key (kbd "C-c C-f") 'cc-fori)
|
(local-set-key (kbd "C-c C-f") 'cc-fori)
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
;; LaTeX setup
|
;; LaTeX setup
|
||||||
|
|
||||||
(setq latex-block-default "itemize")
|
(setq latex-block-default "itemize")
|
||||||
(setq latex-standard-block-names '("description" "listing" "quote" "verbatim"))
|
(setq latex-block-names '("description" "listing" "quote" "verbatim"))
|
||||||
|
|
||||||
(add-hook-and-eval
|
(add-hook-and-eval
|
||||||
'latex-mode-hook
|
'latex-mode-hook
|
||||||
|
@ -48,7 +48,6 @@
|
||||||
(set (make-local-variable 'tex-extension-list)
|
(set (make-local-variable 'tex-extension-list)
|
||||||
'("aux" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy"))
|
'("aux" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy"))
|
||||||
(set (make-local-variable 'tex-command) "pdflatex")
|
(set (make-local-variable 'tex-command) "pdflatex")
|
||||||
(tex-set-compiler)
|
|
||||||
;; For some unknown reasons, `skeleton-end-hook' is set to nil in tex-mode.
|
;; For some unknown reasons, `skeleton-end-hook' is set to nil in tex-mode.
|
||||||
(add-hook 'skeleton-end-hook 'skeleton-make-markers)
|
(add-hook 'skeleton-end-hook 'skeleton-make-markers)
|
||||||
(local-set-key (kbd "C-c C-a") 'latex-article)
|
(local-set-key (kbd "C-c C-a") 'latex-article)
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
;;==============================================================================
|
||||||
|
;; Octave
|
||||||
|
;;==============================================================================
|
||||||
|
|
||||||
;; Set comments to be '%' to be matlab-compatible.
|
;; Set comments to be '%' to be matlab-compatible.
|
||||||
(add-hook
|
(add-hook
|
||||||
'octave-mode-hook
|
'octave-mode-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(set (make-local-variable 'comment-start) "% ")
|
(set (make-local-variable 'comment-start) "% ")))
|
||||||
))
|
|
||||||
|
|
||||||
(provide 'mode-octave)
|
(provide 'mode-octave)
|
||||||
|
|
|
@ -2,16 +2,10 @@
|
||||||
;; Perl
|
;; Perl
|
||||||
;;==============================================================================
|
;;==============================================================================
|
||||||
|
|
||||||
(defun perl-set-interpreter ()
|
|
||||||
"Use compile to run perl programs."
|
|
||||||
(interactive)
|
|
||||||
(set (make-local-variable 'compile-command)
|
|
||||||
(concat "perl " buffer-file-name)))
|
|
||||||
|
|
||||||
(add-hook
|
(add-hook
|
||||||
'python-mode-hook
|
'python-mode-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(set (make-local-variable 'compilation-scroll-output) t)
|
(set (make-local-variable 'compilation-scroll-output) t)
|
||||||
(perl-set-interpreter)))
|
(set (make-local-variable 'compile-command) (concat "perl " buffer-file-name))))
|
||||||
|
|
||||||
(provide 'mode-perl)
|
(provide 'mode-perl)
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
'python-mode-hook
|
'python-mode-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(set (make-local-variable 'compilation-scroll-output) t)
|
(set (make-local-variable 'compilation-scroll-output) t)
|
||||||
(python-set-interpreter)))
|
(add-hook 'compilation-before-hook 'python-set-interpreter)))
|
||||||
|
|
||||||
;; Doc lookup. Requires the python.info file to be installed. See
|
;; Doc lookup. Requires the python.info file to be installed. See
|
||||||
;; https://bitbucket.org/jonwaltman/pydoc-info/.
|
;; https://bitbucket.org/jonwaltman/pydoc-info/.
|
||||||
|
|
|
@ -36,29 +36,14 @@
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; FUNCTIONS
|
;; FUNCTIONS
|
||||||
(defun tex-set-compiler ()
|
(defun tex-set-compiler ()
|
||||||
"Set `compile-command' for TeX-based document.
|
"Set `compile-command' for TeX-based document."
|
||||||
Use a prefix argument to append the '-shell-escape' option to the
|
|
||||||
compile options. This will enable the use of '\write18{<external
|
|
||||||
command>}' from within TeX documents, which need to allow
|
|
||||||
external application to be called from TeX.
|
|
||||||
|
|
||||||
This may be useful for some features like GnuPlot support with TikZ.
|
|
||||||
|
|
||||||
WARNING: the -shell-escape option is a potential security issue."
|
|
||||||
(interactive)
|
|
||||||
(hack-local-variables)
|
(hack-local-variables)
|
||||||
(let (;; Master file.
|
(let (;; Master file.
|
||||||
(local-master
|
(local-master
|
||||||
(if masterfile masterfile buffer-file-name))
|
(if masterfile masterfile (if buffer-file-name buffer-file-name (error "Buffer has no file name")))))
|
||||||
|
|
||||||
;; Support of prefix argument to toggle -shell-escape.
|
|
||||||
(local-shell-escape
|
|
||||||
(if (equal current-prefix-arg '(4)) "-shell-escape" "")))
|
|
||||||
|
|
||||||
(set (make-local-variable 'compile-command)
|
(set (make-local-variable 'compile-command)
|
||||||
(concat tex-command
|
(concat tex-command
|
||||||
" " tex-start-options
|
" " tex-start-options
|
||||||
" " local-shell-escape
|
|
||||||
" " tex-start-commands
|
" " tex-start-commands
|
||||||
" " (shell-quote-argument local-master)))))
|
" " (shell-quote-argument local-master)))))
|
||||||
|
|
||||||
|
@ -118,7 +103,7 @@ but there is no warranty."
|
||||||
;; (set (make-local-variable 'use-hard-newlines) t)
|
;; (set (make-local-variable 'use-hard-newlines) t)
|
||||||
(local-set-key (kbd "<f9>") 'tex-pdf-view)
|
(local-set-key (kbd "<f9>") 'tex-pdf-view)
|
||||||
(setq tex-command "pdftex")
|
(setq tex-command "pdftex")
|
||||||
(tex-set-compiler)))
|
(add-hook 'compilation-before-hook 'tex-set-compiler)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Skeletons
|
;; Skeletons
|
||||||
|
|
Loading…
Reference in New Issue