Emacs: global compilation update, improved support for python, C/C++, TeX
parent
b70b52f7d0
commit
961492416f
|
@ -69,7 +69,6 @@
|
||||||
;; Disable suspend key since it is useless on Emacs server.
|
;; Disable suspend key since it is useless on Emacs server.
|
||||||
(global-unset-key (kbd "C-z"))
|
(global-unset-key (kbd "C-z"))
|
||||||
(global-unset-key (kbd "C-x C-z"))
|
(global-unset-key (kbd "C-x C-z"))
|
||||||
(global-unset-key (kbd "<f10>"))
|
|
||||||
|
|
||||||
;; For convenience.
|
;; For convenience.
|
||||||
(setq inhibit-startup-screen t)
|
(setq inhibit-startup-screen t)
|
||||||
|
@ -319,6 +318,14 @@
|
||||||
(speedbar-toggle-updates)))
|
(speedbar-toggle-updates)))
|
||||||
|
|
||||||
;; Compilation .
|
;; 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 "<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)
|
||||||
|
|
||||||
|
@ -516,3 +523,6 @@ has errors and/or warnings."
|
||||||
|
|
||||||
;; Bookmark file to cache folder
|
;; Bookmark file to cache folder
|
||||||
(setq bookmark-default-file (concat emacs-cache-folder "emacs.bmk"))
|
(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)))
|
||||||
|
|
|
@ -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,
|
then it shall return the name of FILE in the current directory,
|
||||||
suitable for creation"
|
suitable for creation"
|
||||||
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
|
(let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
|
||||||
(expand-file-name file
|
(expand-file-name
|
||||||
(loop
|
file
|
||||||
for d = default-directory then (expand-file-name ".." d)
|
(loop
|
||||||
if (file-exists-p (expand-file-name file d))
|
for d = default-directory then (expand-file-name ".." d)
|
||||||
return d
|
if (file-exists-p (expand-file-name file d))
|
||||||
if (equal d root)
|
return d
|
||||||
return nil))))
|
if (equal d root)
|
||||||
|
return nil))))
|
||||||
|
|
||||||
(defcustom mode-cc-ldlibs "-lm -pthread"
|
(defcustom mode-cc-ldlibs "-lm -pthread"
|
||||||
"[Local variable] Custom linker flags for C/C++ linkage."
|
"[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."
|
"[Local variable] Custom linker libs for C/C++ linkage."
|
||||||
:safe 'stringp)
|
:safe 'stringp)
|
||||||
|
|
||||||
|
(defun cc-set-compiler ()
|
||||||
(defun mode-cc-compile ()
|
"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)
|
(interactive)
|
||||||
(if (get-closest-pathname)
|
(if (get-closest-pathname)
|
||||||
(set (make-local-variable 'compile-command) (format "make -k -f %s" (get-closest-pathname)))
|
(set (make-local-variable 'compile-command) (format "make -k -f %s" (get-closest-pathname)))
|
||||||
(set (make-local-variable 'compile-command)
|
(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
|
(let
|
||||||
((is-cpp (= major-mode "c++-mode"))
|
((is-cpp (= major-mode "c++-mode"))
|
||||||
(file (file-name-nondirectory buffer-file-name)))
|
(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 "CFLAGS") "-ansi -pedantic -std=c99 -Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0"))
|
||||||
(or (getenv "LDFLAGS") mode-cc-ldflags)
|
(or (getenv "LDFLAGS") mode-cc-ldflags)
|
||||||
(or (getenv "LDLIBS") mode-cc-ldlibs)
|
(or (getenv "LDLIBS") mode-cc-ldlibs)
|
||||||
file))))
|
file)))))
|
||||||
(compile compile-command))
|
|
||||||
|
|
||||||
|
|
||||||
;;==============================================================================
|
;;==============================================================================
|
||||||
;; C-mode
|
;; C-mode
|
||||||
|
@ -66,7 +61,7 @@ suitable for creation"
|
||||||
(add-hook
|
(add-hook
|
||||||
'c-mode-hook
|
'c-mode-hook
|
||||||
(lambda ()
|
(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 "M-TAB") 'semantic-complete-analyze-inline)
|
||||||
(local-set-key (kbd "C-M-e") (lambda () (interactive) (c-beginning-of-defun -1)))
|
(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.
|
;; (local-set-key "." 'semantic-complete-self-insert) ; This is a bit slow.
|
||||||
|
@ -97,7 +92,7 @@ suitable for creation"
|
||||||
(add-hook
|
(add-hook
|
||||||
'c++-mode-hook
|
'c++-mode-hook
|
||||||
(lambda ()
|
(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 "C-M-e") (lambda () (interactive) (c-beginning-of-defun -1)))
|
||||||
(local-set-key (kbd "M-TAB") 'semantic-complete-analyze-inline)))
|
(local-set-key (kbd "M-TAB") 'semantic-complete-analyze-inline)))
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
;; Python
|
;; Python
|
||||||
;;==============================================================================
|
;;==============================================================================
|
||||||
|
|
||||||
(defcustom python-compiler ""
|
(defcustom python-interpreter nil
|
||||||
"Python compiler."
|
"Python interpreter. If value is nil, the shabang will be
|
||||||
|
checked, and if no shabang is present, `python' will be used."
|
||||||
:safe 'stringp)
|
:safe 'stringp)
|
||||||
|
|
||||||
(defun python-version ()
|
(defun python-version ()
|
||||||
|
@ -17,21 +18,21 @@ shebang. System `python' is assumed by default."
|
||||||
((string-match "python3" firstline) "python3")
|
((string-match "python3" firstline) "python3")
|
||||||
(t "python")))))
|
(t "python")))))
|
||||||
|
|
||||||
(defun python-compile ()
|
(defun python-set-interpreter ()
|
||||||
"Use compile to run python programs."
|
"Use compile to run python programs."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((py-compiler
|
(let ((py-interpreter
|
||||||
(if (equal python-compiler "")
|
(if python-interpreter
|
||||||
(python-version)
|
python-interpreter
|
||||||
python-compiler)))
|
(python-version))))
|
||||||
(save-buffer)
|
(set (make-local-variable 'compile-command)
|
||||||
(compile (concat py-compiler " '" buffer-file-name "'"))))
|
(concat py-interpreter " " 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)
|
||||||
(local-set-key (kbd "<f10>") 'python-compile)) t)
|
(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/.
|
||||||
|
|
|
@ -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."
|
TeX mode, and latex-my-default-compiler for LaTeX mode."
|
||||||
:safe 'stringp)
|
:safe 'stringp)
|
||||||
|
|
||||||
(defcustom tex-my-masterfile nil
|
(defcustom masterfile nil
|
||||||
"[Local variable]
|
"[Local variable]
|
||||||
|
|
||||||
The file that should be compiled."
|
The file that should be compiled."
|
||||||
|
@ -96,7 +96,7 @@ document, you may define it here:
|
||||||
\\def\\myvar{mycontent}"
|
\\def\\myvar{mycontent}"
|
||||||
:safe 'stringp)
|
:safe 'stringp)
|
||||||
|
|
||||||
(defun tex-my-compile ()
|
(defun tex-set-compiler ()
|
||||||
"Use compile to process your TeX-based document. Use a prefix
|
"Use compile to process your TeX-based document. Use a prefix
|
||||||
argument to call the compiler along the '-shell-escape'
|
argument to call the compiler along the '-shell-escape'
|
||||||
option. This will enable the use of '\write18{<external
|
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
|
;; Master file
|
||||||
(local-master
|
(local-master
|
||||||
(if (not tex-my-masterfile)
|
(if (not masterfile)
|
||||||
buffer-file-name
|
buffer-file-name
|
||||||
tex-my-masterfile))
|
masterfile))
|
||||||
|
|
||||||
;; If tex-my-startcommands has some content, we make sure it is a string
|
;; If tex-my-startcommands has some content, we make sure it is a string
|
||||||
;; that loads the file.
|
;; that loads the file.
|
||||||
|
@ -134,22 +134,11 @@ WARNING: the -shell-escape option is a potential security issue."
|
||||||
(local-shell-escape
|
(local-shell-escape
|
||||||
(if (equal current-prefix-arg '(4)) "-shell-escape" "")))
|
(if (equal current-prefix-arg '(4)) "-shell-escape" "")))
|
||||||
|
|
||||||
(let (
|
(set (make-local-variable 'compile-command)
|
||||||
;; Final command
|
(concat local-compiler " " local-shell-escape " " tex-my-compiler-options " " local-start-cmd " \"" local-master "\""))))
|
||||||
(local-compile-command
|
|
||||||
(concat local-compiler " " local-shell-escape " " tex-my-compiler-options " " local-start-cmd " \"" local-master "\"")))
|
|
||||||
|
|
||||||
;; (message local-compile-command) ;; Debug only.
|
(defcustom tex-my-extension-list
|
||||||
(save-buffer)
|
'("aux" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy")
|
||||||
(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")
|
|
||||||
"List of known TeX exentsions. This list is used by 'tex-clean to purge all matching files."
|
"List of known TeX exentsions. This list is used by 'tex-clean to purge all matching files."
|
||||||
:safe 'listp)
|
:safe 'listp)
|
||||||
|
|
||||||
|
@ -160,9 +149,9 @@ but there is no warranty."
|
||||||
(let (
|
(let (
|
||||||
;; Master file.
|
;; Master file.
|
||||||
(local-master
|
(local-master
|
||||||
(if (not tex-my-masterfile)
|
(if (not masterfile)
|
||||||
buffer-file-name
|
buffer-file-name
|
||||||
tex-my-masterfile)))
|
masterfile)))
|
||||||
|
|
||||||
(let (
|
(let (
|
||||||
;; File name without extension.
|
;; File name without extension.
|
||||||
|
@ -189,9 +178,9 @@ your document embeds raster graphics."
|
||||||
(let (
|
(let (
|
||||||
;; Master file.
|
;; Master file.
|
||||||
(local-master
|
(local-master
|
||||||
(if (not tex-my-masterfile)
|
(if (not masterfile)
|
||||||
buffer-file-name
|
buffer-file-name
|
||||||
tex-my-masterfile)))
|
masterfile)))
|
||||||
|
|
||||||
(let (
|
(let (
|
||||||
;; Temp compressed file.
|
;; Temp compressed file.
|
||||||
|
@ -215,9 +204,9 @@ properly escaped with double-quotes in case it has spaces."
|
||||||
(let (
|
(let (
|
||||||
;; Master file.
|
;; Master file.
|
||||||
(local-master
|
(local-master
|
||||||
(if (not tex-my-masterfile)
|
(if (not masterfile)
|
||||||
buffer-file-name
|
buffer-file-name
|
||||||
tex-my-masterfile)))
|
masterfile)))
|
||||||
|
|
||||||
(shell-command
|
(shell-command
|
||||||
(concat tex-my-viewer
|
(concat tex-my-viewer
|
||||||
|
@ -231,5 +220,7 @@ properly escaped with double-quotes in case it has spaces."
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(dolist (key '("\C-c\C-f" "\C-c\C-b"))
|
(dolist (key '("\C-c\C-f" "\C-c\C-b"))
|
||||||
(local-unset-key key))
|
(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) ))
|
(local-set-key (kbd "<f9>") 'tex-pdf-view) ))
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
tex-mode
|
|
Loading…
Reference in New Issue