Emacs: global compilation update, improved support for python, C/C++, TeX

master
Pierre Neidhardt 2013-07-04 10:37:18 +02:00
parent b70b52f7d0
commit 961492416f
5 changed files with 54 additions and 58 deletions

View File

@ -69,7 +69,6 @@
;; Disable suspend key since it is useless on Emacs server.
(global-unset-key (kbd "C-z"))
(global-unset-key (kbd "C-x C-z"))
(global-unset-key (kbd "<f10>"))
;; For convenience.
(setq inhibit-startup-screen t)
@ -319,6 +318,14 @@
(speedbar-toggle-updates)))
;; Compilation .
(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*"))))
(define-key my-keys-minor-mode-map (kbd "<f11>") 'previous-error)
(define-key my-keys-minor-mode-map (kbd "<f12>") 'next-error)
@ -516,3 +523,6 @@ has errors and/or warnings."
;; Bookmark file to cache folder
(setq bookmark-default-file (concat emacs-cache-folder "emacs.bmk"))
;; Code browsing
(define-key my-keys-minor-mode-map (kbd "C-M-e") (lambda () (interactive) (beginning-of-defun -1)))

View File

@ -11,14 +11,14 @@ correct thing in presence of links. If it does not find FILE,
then it shall return the name of FILE in the current directory,
suitable for creation"
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
(expand-file-name file
(loop
for d = default-directory then (expand-file-name ".." d)
if (file-exists-p (expand-file-name file d))
return d
if (equal d root)
return nil))))
(expand-file-name
file
(loop
for d = default-directory then (expand-file-name ".." d)
if (file-exists-p (expand-file-name file d))
return d
if (equal d root)
return nil))))
(defcustom mode-cc-ldlibs "-lm -pthread"
"[Local variable] Custom linker flags for C/C++ linkage."
@ -28,17 +28,14 @@ suitable for creation"
"[Local variable] Custom linker libs for C/C++ linkage."
:safe 'stringp)
(defun mode-cc-compile ()
(defun cc-set-compiler ()
"Set C/C++ compile command to be nearest Makefile found in
parent folders. If no Makefile is found, then a configurable
command line is provided."
(interactive)
(if (get-closest-pathname)
(set (make-local-variable 'compile-command) (format "make -k -f %s" (get-closest-pathname)))
(set (make-local-variable 'compile-command)
;; Emulate make's .c.o implicit pattern rule, but with
;; different defaults for the CC, CPPFLAGS, and CFLAGS
;; variables:
;; $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
;; (setq compile-command
(let
((is-cpp (= major-mode "c++-mode"))
(file (file-name-nondirectory buffer-file-name)))
@ -52,9 +49,7 @@ suitable for creation"
(or (getenv "CFLAGS") "-ansi -pedantic -std=c99 -Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0"))
(or (getenv "LDFLAGS") mode-cc-ldflags)
(or (getenv "LDLIBS") mode-cc-ldlibs)
file))))
(compile compile-command))
file)))))
;;==============================================================================
;; C-mode
@ -66,7 +61,7 @@ suitable for creation"
(add-hook
'c-mode-hook
(lambda ()
(local-set-key (kbd "<f10>") 'mode-cc-compile)
(cc-set-compiler)
(local-set-key (kbd "M-TAB") 'semantic-complete-analyze-inline)
(local-set-key (kbd "C-M-e") (lambda () (interactive) (c-beginning-of-defun -1)))
;; (local-set-key "." 'semantic-complete-self-insert) ; This is a bit slow.
@ -97,7 +92,7 @@ suitable for creation"
(add-hook
'c++-mode-hook
(lambda ()
(local-set-key (kbd "<f10>") 'mode-cc-compile)
(cc-set-compiler)
(local-set-key (kbd "C-M-e") (lambda () (interactive) (c-beginning-of-defun -1)))
(local-set-key (kbd "M-TAB") 'semantic-complete-analyze-inline)))

View File

@ -2,8 +2,9 @@
;; Python
;;==============================================================================
(defcustom python-compiler ""
"Python compiler."
(defcustom python-interpreter nil
"Python interpreter. If value is nil, the shabang will be
checked, and if no shabang is present, `python' will be used."
:safe 'stringp)
(defun python-version ()
@ -17,21 +18,21 @@ shebang. System `python' is assumed by default."
((string-match "python3" firstline) "python3")
(t "python")))))
(defun python-compile ()
(defun python-set-interpreter ()
"Use compile to run python programs."
(interactive)
(let ((py-compiler
(if (equal python-compiler "")
(python-version)
python-compiler)))
(save-buffer)
(compile (concat py-compiler " '" buffer-file-name "'"))))
(let ((py-interpreter
(if python-interpreter
python-interpreter
(python-version))))
(set (make-local-variable 'compile-command)
(concat py-interpreter " " buffer-file-name))))
(add-hook
'python-mode-hook
(lambda ()
(set (make-local-variable 'compilation-scroll-output) t)
(local-set-key (kbd "<f10>") 'python-compile)) t)
(python-set-interpreter)))
;; Doc lookup. Requires the python.info file to be installed. See
;; https://bitbucket.org/jonwaltman/pydoc-info/.

View File

@ -32,7 +32,7 @@ If value is nil, the compiler will be tex-my-default-compiler for
TeX mode, and latex-my-default-compiler for LaTeX mode."
:safe 'stringp)
(defcustom tex-my-masterfile nil
(defcustom masterfile nil
"[Local variable]
The file that should be compiled."
@ -96,7 +96,7 @@ document, you may define it here:
\\def\\myvar{mycontent}"
:safe 'stringp)
(defun tex-my-compile ()
(defun tex-set-compiler ()
"Use compile to process your TeX-based document. Use a prefix
argument to call the compiler along the '-shell-escape'
option. This will enable the use of '\write18{<external
@ -120,9 +120,9 @@ WARNING: the -shell-escape option is a potential security issue."
;; Master file
(local-master
(if (not tex-my-masterfile)
(if (not masterfile)
buffer-file-name
tex-my-masterfile))
masterfile))
;; If tex-my-startcommands has some content, we make sure it is a string
;; that loads the file.
@ -134,22 +134,11 @@ WARNING: the -shell-escape option is a potential security issue."
(local-shell-escape
(if (equal current-prefix-arg '(4)) "-shell-escape" "")))
(let (
;; Final command
(local-compile-command
(concat local-compiler " " local-shell-escape " " tex-my-compiler-options " " local-start-cmd " \"" local-master "\"")))
(set (make-local-variable 'compile-command)
(concat local-compiler " " local-shell-escape " " tex-my-compiler-options " " local-start-cmd " \"" local-master "\""))))
;; (message local-compile-command) ;; Debug only.
(save-buffer)
(setq compilation-scroll-output t)
(compile local-compile-command)
;; If no user interaction for 2 seconds, hide the compilation window.
(sit-for 2)
(delete-windows-on "*compilation*"))))
(defcustom tex-my-extension-list '("aux" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy")
(defcustom tex-my-extension-list
'("aux" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy")
"List of known TeX exentsions. This list is used by 'tex-clean to purge all matching files."
:safe 'listp)
@ -160,9 +149,9 @@ but there is no warranty."
(let (
;; Master file.
(local-master
(if (not tex-my-masterfile)
(if (not masterfile)
buffer-file-name
tex-my-masterfile)))
masterfile)))
(let (
;; File name without extension.
@ -189,9 +178,9 @@ your document embeds raster graphics."
(let (
;; Master file.
(local-master
(if (not tex-my-masterfile)
(if (not masterfile)
buffer-file-name
tex-my-masterfile)))
masterfile)))
(let (
;; Temp compressed file.
@ -215,9 +204,9 @@ properly escaped with double-quotes in case it has spaces."
(let (
;; Master file.
(local-master
(if (not tex-my-masterfile)
(if (not masterfile)
buffer-file-name
tex-my-masterfile)))
masterfile)))
(shell-command
(concat tex-my-viewer
@ -231,5 +220,7 @@ properly escaped with double-quotes in case it has spaces."
(lambda ()
(dolist (key '("\C-c\C-f" "\C-c\C-b"))
(local-unset-key key))
(local-set-key (kbd "<f10>") 'tex-my-compile)
(tex-set-compiler)
(set (make-local-variable 'compilation-scroll-output) t)
(set (make-local-variable 'compilation-hide-window) t)
(local-set-key (kbd "<f9>") 'tex-pdf-view) ))

View File

@ -1 +0,0 @@
tex-mode