Emacs: compile--hook and dynamic compile-command for every mode
parent
36af4a2e10
commit
a3e3cd1d2f
|
@ -241,16 +241,39 @@
|
|||
(speedbar-toggle-updates)))
|
||||
|
||||
;; Compilation bindings and conveniences.
|
||||
(setq compilation-hide-window nil)
|
||||
(define-key my-keys-minor-mode-map (kbd "<f10>")
|
||||
(lambda () (interactive)
|
||||
(save-buffer)
|
||||
(compile compile-command)
|
||||
(when compilation-hide-window
|
||||
(sit-for 2)
|
||||
(delete-windows-on "*compilation*"))))
|
||||
(defvar compilation-time-before-hide-window nil
|
||||
"Hide compilation window after the specified seconds.
|
||||
If nil, do not hide.")
|
||||
(defcustom compilation-before-hook nil
|
||||
"List of hook functions run by `compile-custom'."
|
||||
:type 'hook
|
||||
:group '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 "<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.
|
||||
(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
|
||||
found, then a configurable command line is provided.\n
|
||||
Requires `get-closest-pathname'."
|
||||
(require 'functions)
|
||||
(interactive)
|
||||
(require 'functions)
|
||||
(hack-local-variables)
|
||||
(let ((makefile (get-closest-pathname)))
|
||||
(if makefile
|
||||
(set (make-local-variable 'compile-command) (format "make -k -f %s" makefile))
|
||||
(set (make-local-variable 'compile-command)
|
||||
(let
|
||||
((is-cpp (eq major-mode 'c++-mode))
|
||||
((cppp (eq major-mode 'c++-mode))
|
||||
(file (file-name-nondirectory buffer-file-name)))
|
||||
(format "%s %s -o %s %s %s %s"
|
||||
(if is-cpp
|
||||
(if cppp
|
||||
(or (getenv "CXX") "g++")
|
||||
(or (getenv "CC") "gcc"))
|
||||
file
|
||||
(file-name-sans-extension file)
|
||||
(if is-cpp
|
||||
(if cppp
|
||||
(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 "LDFLAGS") cc-ldflags)
|
||||
|
@ -79,7 +80,7 @@ restored."
|
|||
mode-hook
|
||||
(lambda ()
|
||||
(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 "M-TAB") 'semantic-complete-analyze-inline)
|
||||
(local-set-key (kbd "C-c C-f") 'cc-fori)
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
;; LaTeX setup
|
||||
|
||||
(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
|
||||
'latex-mode-hook
|
||||
|
@ -48,7 +48,6 @@
|
|||
(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"))
|
||||
(set (make-local-variable 'tex-command) "pdflatex")
|
||||
(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 C-a") 'latex-article)
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
;;==============================================================================
|
||||
;; Octave
|
||||
;;==============================================================================
|
||||
|
||||
;; Set comments to be '%' to be matlab-compatible.
|
||||
(add-hook
|
||||
'octave-mode-hook
|
||||
(lambda ()
|
||||
(set (make-local-variable 'comment-start) "% ")
|
||||
))
|
||||
(set (make-local-variable 'comment-start) "% ")))
|
||||
|
||||
(provide 'mode-octave)
|
||||
|
|
|
@ -2,16 +2,10 @@
|
|||
;; 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
|
||||
'python-mode-hook
|
||||
(lambda ()
|
||||
(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)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
'python-mode-hook
|
||||
(lambda ()
|
||||
(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
|
||||
;; https://bitbucket.org/jonwaltman/pydoc-info/.
|
||||
|
|
|
@ -36,29 +36,14 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; FUNCTIONS
|
||||
(defun tex-set-compiler ()
|
||||
"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)
|
||||
"Set `compile-command' for TeX-based document."
|
||||
(hack-local-variables)
|
||||
(let (;; Master file.
|
||||
(local-master
|
||||
(if masterfile masterfile buffer-file-name))
|
||||
|
||||
;; Support of prefix argument to toggle -shell-escape.
|
||||
(local-shell-escape
|
||||
(if (equal current-prefix-arg '(4)) "-shell-escape" "")))
|
||||
|
||||
(if masterfile masterfile (if buffer-file-name buffer-file-name (error "Buffer has no file name")))))
|
||||
(set (make-local-variable 'compile-command)
|
||||
(concat tex-command
|
||||
" " tex-start-options
|
||||
" " local-shell-escape
|
||||
" " tex-start-commands
|
||||
" " (shell-quote-argument local-master)))))
|
||||
|
||||
|
@ -118,7 +103,7 @@ but there is no warranty."
|
|||
;; (set (make-local-variable 'use-hard-newlines) t)
|
||||
(local-set-key (kbd "<f9>") 'tex-pdf-view)
|
||||
(setq tex-command "pdftex")
|
||||
(tex-set-compiler)))
|
||||
(add-hook 'compilation-before-hook 'tex-set-compiler)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Skeletons
|
||||
|
|
Loading…
Reference in New Issue