Emacs: cleaned cc-set-compiler and set cc-ld* variables as local

master
Pierre Neidhardt 2014-03-08 16:31:41 +01:00
parent d7894f697e
commit ac4abd5e7f
2 changed files with 29 additions and 24 deletions

View File

@ -141,9 +141,10 @@ A page boundary is any line whose beginning matches the regexp
(defun get-closest-pathname (&optional file) (defun get-closest-pathname (&optional file)
"Get pathname of the first instance of FILE towards root. "Get pathname of the first instance of FILE towards root.
This may not do the correct thing in presence of links. If it If FILE is unspecified, look for 'Makefile'. If it does not find
does not find FILE, then it shall return the name of FILE in the FILE, then it shall return the name of FILE in the current
current directory, suitable for creation" directory, suitable for creation. This may not do the correct
thing in presence of links."
(let ((current-dir default-directory) (looping t) (makefile (or file "Makefile"))) (let ((current-dir default-directory) (looping t) (makefile (or file "Makefile")))
(while (progn (while (progn
(if (file-exists-p (expand-file-name makefile current-dir)) (if (file-exists-p (expand-file-name makefile current-dir))

View File

@ -3,12 +3,14 @@
;;============================================================================== ;;==============================================================================
(defcustom cc-ldlibs "-lm -pthread" (defcustom cc-ldlibs "-lm -pthread"
"[Local variable] Custom linker flags for C/C++ linkage." "Custom linker flags for C/C++ linkage."
:safe 'stringp) :safe 'stringp)
(make-variable-buffer-local 'cc-ldlibs)
(defcustom cc-ldflags "" (defcustom cc-ldflags ""
"[Local variable] Custom linker libs for C/C++ linkage." "Custom linker libs for C/C++ linkage."
:safe 'stringp) :safe 'stringp)
(make-variable-buffer-local 'cc-ldflags)
(defun cc-set-compiler () (defun cc-set-compiler ()
"Set compile command to be nearest Makefile. "Set compile command to be nearest Makefile.
@ -17,23 +19,24 @@ found, then a configurable command line is provided.\n
Requires `get-closest-pathname'." Requires `get-closest-pathname'."
(require 'functions) (require 'functions)
(interactive) (interactive)
(if (get-closest-pathname) (let ((makefile (get-closest-pathname)))
(set (make-local-variable 'compile-command) (format "make -k -f %s" (get-closest-pathname))) (if makefile
(set (make-local-variable 'compile-command) (set (make-local-variable 'compile-command) (format "make -k -f %s" makefile))
(let (set (make-local-variable 'compile-command)
((is-cpp (equal (symbol-name major-mode) "c++-mode")) (let
(file (file-name-nondirectory buffer-file-name))) ((is-cpp (eq major-mode 'c++-mode))
(format "%s %s -o %s %s %s %s" (file (file-name-nondirectory buffer-file-name)))
(if is-cpp (format "%s %s -o %s %s %s %s"
(or (getenv "CXX") "g++") (if is-cpp
(or (getenv "CC") "gcc")) (or (getenv "CXX") "g++")
file (or (getenv "CC") "gcc"))
(file-name-sans-extension file) file
(if is-cpp (file-name-sans-extension file)
(or (getenv "CPPFLAGS") "-Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0") (if is-cpp
(or (getenv "CFLAGS") "-ansi -pedantic -std=c99 -Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0")) (or (getenv "CPPFLAGS") "-Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0")
(or (getenv "LDFLAGS") cc-ldflags) (or (getenv "CFLAGS") "-ansi -pedantic -std=c99 -Wall -Wextra -Wshadow -DDEBUG=9 -g3 -O0"))
(or (getenv "LDLIBS") cc-ldlibs)))))) (or (getenv "LDFLAGS") cc-ldflags)
(or (getenv "LDLIBS") cc-ldlibs)))))))
(defun cc-clean () (defun cc-clean ()
"Find Makefile and call the `clean' rule. If no Makefile is "Find Makefile and call the `clean' rule. If no Makefile is
@ -115,8 +118,9 @@ restored."
;; Skel ;; Skel
;;============================================================================== ;;==============================================================================
;; Note that it is possible to extend the skel syntax like this: (setq ;; Note that it is possible to extend the skel syntax with
;; skeleton-further-elements '((q "\""))) ;; `skeleton-further-elements'. For instance:
; (setq skeleton-further-elements '((q "\"")))
(define-skeleton cc-printf (define-skeleton cc-printf
"fprintf/printf snippet. "fprintf/printf snippet.