Skip to content

Instantly share code, notes, and snippets.

@santanuchakrabarti
Last active August 29, 2015 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save santanuchakrabarti/2a9d96ea838f482c51dd to your computer and use it in GitHub Desktop.
Save santanuchakrabarti/2a9d96ea838f482c51dd to your computer and use it in GitHub Desktop.
Emacs configuration file (.emacs) - For Common Lisp and SLIME, Scheme and Geiser, Clojure, Java and ANSI C
(add-to-list 'load-path "~/.emacs.d/include")
(add-to-list 'load-path "~/.emacs.d/ecb")
(add-to-list 'load-path "~/.emacs.d/full-ack")
(autoload 'ack-same "full-ack" nil t)
(autoload 'ack "full-ack" nil t)
(autoload 'ack-find-same-file "full-ack" nil t)
(autoload 'ack-find-file "full-ack" nil t)
(setq cedet-custom-path "~/.emacs.d/cedet-1.0.1") ;; takes care of loading cedet-1.1
(require 'ideframetools)
;;(load-file "~/.emacs.d/cedet-1.1/common/cedet.el")
;;(global-ede-mode 1) ; Enable the Project management system
;;(semantic-load-enable-code-helpers) ; Enable prototype help and smart completion
;;(global-srecode-minor-mode 1) ; Enable template insertion menu
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ecb-auto-activate t)
'(ecb-layout-name "leftright2")
'(ecb-layout-window-sizes (quote (("leftright2" (ecb-directories-buffer-name 0.19879518072289157 . 0.6216216216216216) (ecb-sources-buffer-name 0.19879518072289157 . 0.35135135135135137) (ecb-methods-buffer-name 0.19879518072289157 . 0.6216216216216216) (ecb-history-buffer-name 0.19879518072289157 . 0.35135135135135137)) ("left2" (ecb-directories-buffer-name 0.3203125 . 0.5) (ecb-sources-buffer-name 0.3203125 . 0.4722222222222222)) ("left9" (ecb-methods-buffer-name 0.33043478260869563 . 0.9722222222222222)))))
'(ecb-options-version "2.40")
'(ecb-primary-secondary-mouse-buttons (quote mouse-1--C-mouse-1))
'(ecb-show-sources-in-directories-buffer (quote always))
'(ecb-source-file-regexps (quote ((".*" ("") ("")))))
'(ecb-source-path (quote (("/host/santanu/programming/Lisp" "Lisp Projects") ("/host/santanu/programming/c_projects" "C Projects") ("/host/santanu/programming/java" "Java Projects"))))
'(ecb-tip-of-the-day nil)
'(initial-frame-alist (quote ((menu-bar-lines . 1) (tool-bar-lines . 1) (fullscreen . maximized))))
'(jde-check-version-flag nil)
'(jde-compiler (quote (("eclipse java compiler server" "/host/santanu/programming/java/ext-lib/ecj-4.4.jar"))))
'(jde-jdk (quote ("1.7")))
'(jde-jdk-registry (quote (("1.6" . "/usr/lib/jvm/java-6-sun") ("1.7" . "/usr/lib/jvm/jdk1.7.0_67"))))
'(safe-local-variable-values (quote ((project-root . "/host/santanu/programming/c_projects/configurator") (check-code-style . "bash cbuild.c analyse_rsm") (project-root . "/host/santanu/programming/c_projects/filestat") (project-root . /host/santanu/programming/c_projects/filestat))))
'(tags-revert-without-query t)
'(tags-table-list (quote ("/host/santanu/programming/java"))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(flymake-errline ((((class color)) (:underline "OrangeRed"))))
'(flymake-warnline ((((class color)) (:underline "yellow")))))
;; setting up SLIME
(add-to-list 'load-path "/home/santanu/quicklisp/dists/quicklisp/software/slime-2.7")
(require 'slime-autoloads)
;; -- not necessary with slime-autoloads --
;;(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
;;(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))
;; Optionally, specify the lisp program you are using. Default is "lisp"
(setq inferior-lisp-program "clisp")
(setq slime-contribs '(slime-fancy))
(setq show-paren-delay 0)
(setq show-paren-style 'parenthesis)
(show-paren-mode 1)
(make-variable-buffer-local 'show-paren-mode)
(require 'rainbow-delimiters)
(global-rainbow-delimiters-mode)
(cua-mode t)
(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour
;; associate file extensions to syntax modes
(add-to-list 'auto-mode-alist '("\\.emacs\\'" . emacs-lisp-mode))
(add-to-list 'auto-mode-alist '("\\.asd\\'" . lisp-mode))
;;; activate and deactivate ecb
(global-set-key (kbd "C-c .ac") 'ecb-activate)
(global-set-key (kbd "C-c .de") 'ecb-deactivate)
;;; show/hide ecb window
(global-set-key (kbd "C-c .ws") 'ecb-show-ecb-windows)
(global-set-key (kbd "C-c .wh") 'ecb-hide-ecb-windows)
;;; quick navigation between ecb windows
(global-set-key (kbd "C-c .ge") 'ecb-goto-window-edit1)
(global-set-key (kbd "C-c .gd") 'ecb-goto-window-directories)
(global-set-key (kbd "C-c .gs") 'ecb-goto-window-sources)
(global-set-key (kbd "C-c .gm") 'ecb-goto-window-methods)
(global-set-key (kbd "C-c .gc") 'ecb-goto-window-compilation)
(defun open-slime ()
"Opens up REPL in a window below"
(interactive)
(split-window-vertically)
(other-window 1)
(shrink-window 10)
(slime))
;; define key binding for open-slime
(global-set-key (kbd "C-c .$") 'open-slime)
;; adding color theme
(add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0")
(require 'color-theme)
(eval-after-load "color-theme"
'(progn
(color-theme-initialize)
(color-theme-gray30)))
;; set up indent for Common Lisp
(add-hook 'lisp-mode-hook
(lambda ()
(set (make-local-variable 'lisp-indent-function)
'common-lisp-indent-function)))
(require 'indent-file)
(add-hook 'lisp-mode-hook 'indent-file-when-save)
(add-hook 'lisp-mode-hook 'indent-file-when-visit)
;; set up ParEdit for all dialects of Lisp
(autoload 'enable-paredit-mode "paredit"
"Turn on pseudo-structural editing of Lisp code." t)
(add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode)
(add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1)))
;; Stop SLIME's REPL from grabbing DEL,
;; which is annoying when backspacing over a '('
(defun override-slime-repl-bindings-with-paredit ()
(define-key slime-repl-mode-map
(read-kbd-macro paredit-backward-delete-key) nil))
(add-hook 'slime-repl-mode-hook 'override-slime-repl-bindings-with-paredit)
;; set up Geiser
(load-file "~/.emacs.d/geiser-0.7/elisp/geiser.el")
;; set up markdown-mode
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
;; increase Lisp stack size
;;(setq max-lisp-eval-depth 10000)
;; Emacs configs to set up Java
(add-to-list 'load-path "~/.emacs.d/elib-1.0/")
(add-to-list 'load-path "~/.emacs.d/jdee-2.4.1/lisp")
(load "jde")
(autoload 'jde-mode "jde" "JDE mode" t)
(defun my-c-mode-hook ()
(setq indent-tabs-mode nil
compile-command "gradle build"
require-final-newline nil)
(lambda () (auto-fill-mode 1))
(define-key c-mode-base-map (kbd "C-m") 'c-context-line-break)
(global-set-key (kbd "M-n") 'jde-complete-minibuf)
(global-set-key (kbd "M-N") 'jde-complete-menu)
(define-key c-mode-base-map (kbd "C-c C-p") 'show-previous-error)
(define-key c-mode-base-map (kbd "C-c C-n") 'show-next-error)
(c-set-offset 'substatement-open 0))
(add-hook 'c-mode-common-hook 'my-c-mode-hook)
(require 'compile)
(setq compilation-error-regexp-alist
(append (list
;; works for jikes
'("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
;; works for javac
'("^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2)
;; works for maven
'("^\\(.*\\):\\[\\([0-9]*\\),\\([0-9]*\\)\\]" 1 2 3))
compilation-error-regexp-alist))
(require 'jde-ecj-flymake)
(add-hook 'find-file-hook 'flymake-find-file-hook)
(setq compilation-in-progress nil)
(push '("\\.java\\'" jde-ecj-flymake-init jde-ecj-flymake-cleanup) flymake-allowed-file-name-masks)
(require 'jtags)
(autoload 'jtags-mode "jtags" "Toggle jtags mode." t)
(add-hook 'java-mode-hook 'jtags-mode)
(defun exec-build ()
"Executes the build command for a Java or C project"
(interactive)
(split-window-vertically)
(other-window 1)
(shrink-window 10)
(other-window -1)
(let ((dirname)
(dir-buffer nil))
;;(setq dirname (find-build-dir))
;; IF block checks for project type (Java or ANSI C)
;; and sets DIRNAME to project root directory
(if (equal major-mode 'jde-mode)
(setq dirname (find-build-dir))
(if (equal major-mode 'c-mode)
(setq dirname (assoc-default 'project-root file-local-variables-alist))
(setq dirname "")))
(save-excursion
(setq dir-buffer (find-file-noselect dirname))
(set-buffer dir-buffer)
(compile compile-command)
(kill-buffer dir-buffer))))
(global-set-key (kbd "C-c .be") 'exec-build)
(defun find-build-dir ()
"Returns JDE-RUN-WORKING-DIRECTORY if set else tries to find it from current buffer file"
(if jde-run-working-directory jde-run-working-directory
(let ((build-dir)
(curr-buffer-file (buffer-file-name (current-buffer)))
(found nil)
(top nil))
;; set build-dir to current buffer's directory
(setq build-dir (directory-file-name (file-name-directory curr-buffer-file)))
(while (not (or found top))
;; If we're at / set top flag.
(if (string= (expand-file-name build-dir) "/")
(setq top t))
;; Check for the build.gradle file
(if (file-exists-p (expand-file-name "build.gradle" build-dir))
(setq found t)
(setq build-dir (directory-file-name (file-name-directory build-dir)))))
build-dir)))
;; To configure support for ANSI C
(semantic-add-system-include "/usr/include/sys" 'c-mode)
(semantic-add-system-include "/usr/lib/gcc/i686-linux-gnu/4.6.1/include" 'c-mode)
;; Define function flymake-init
;; Ref: http://stackoverflow.com/questions/14864511/configure-emacs-flymake-to-call-g-directly/14866268#14866268
(defun flymake-ansic-init ()
(let* (;; Create temp file which is copy of current file
(temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
;; Get relative path of temp file from current directory
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
;; Construct compile command which is defined list.
;; First element is program name, "gcc" in this case.
;; Second element is list of options.
(list "gcc" (list "-std=c99" "-fno-common" "-fshort-enums" "-pedantic" "-undef"
"-W" "-Waggregate-return" "-Wall" "-Wcast-align" "-Wcast-qual"
"-Wconversion" "-Wmissing-declarations" "-Wredundant-decls"
"-Wmissing-prototypes" "-Wnested-externs" "-Wpointer-arith" "-Wshadow"
"-Wstrict-prototypes" "-Wwrite-strings" "-o" "/dev/null" "-O4" "-g" "-c"
local-file))))
;; Enable above flymake setting for C files(suffix is '.c')
(add-to-list 'flymake-allowed-file-name-masks '("\\.c\\'" flymake-ansic-init))
(add-to-list 'flymake-allowed-file-name-masks '("\\.h\\'" flymake-ansic-init))
(require 'ede)
(global-ede-mode t)
;; c-mode settings for ANSI C
;; Function to run astyle while saving a C code file
(defun astyle-this-buffer ()
(interactive)
(if (buffer-modified-p)
(save-buffer 0))
(shell-command
(format "astyle %s"
(shell-quote-argument (buffer-file-name)))
nil (get-buffer-create "*Astyle Errors*"))
(revert-buffer t t t))
(defun ansi-c-mode-hook ()
"turns off syntactic indentation and sets indent-region-function"
(setq c-syntactic-indentation nil)
(setq compile-command "bash cbuild.c")
(setq enable-local-variables :all)
(setq ac-sources (append '(ac-source-clang) ac-sources))
(local-set-key (kbd "C-c M-a") 'astyle-this-buffer)
(local-set-key (kbd "C-c .te") '(lambda ()
(interactive)
(run-command 'test-command)))
(local-set-key (kbd "C-c .cs") '(lambda ()
(interactive)
(run-command 'check-code-style))))
(add-hook 'c-mode-hook 'ansi-c-mode-hook)
(defun run-command (command-name)
"Executes a command for a C project"
(interactive)
(split-window-vertically)
(other-window 1)
(shrink-window 10)
(other-window -1)
(let ((dirname)
(ext-run-command)
(dir-buffer nil))
(setq dirname (assoc-default 'project-root file-local-variables-alist))
(setq ext-run-command (assoc-default command-name file-local-variables-alist))
(save-excursion
(setq dir-buffer (find-file-noselect dirname))
(set-buffer dir-buffer)
(compile ext-run-command)
(kill-buffer dir-buffer))))
;; code snippets and auto complete
(add-to-list 'load-path "~/.emacs.d/yasnippet")
(require 'yasnippet)
(setq yas-snippet-dirs
'("~/.emacs.d/snippets" ;; personal snippets
"~/.emacs.d/yasnippet/yasmate/snippets" ;; the yasmate collection
"~/.emacs.d/yasnippet/snippets" ;; the default collection
))
(yas-global-mode 1)
(add-to-list 'load-path "~/.emacs.d/auto-complete-1.4.0")
(require 'auto-complete-config)
(ac-config-default)
(setq ac-auto-start nil)
(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab>")
(define-key ac-mode-map (kbd "TAB") 'auto-complete)
(define-key ac-mode-map (kbd "<tab>") 'auto-complete)
(setq popup-use-optimized-column-computation nil)
(setq ac-show-menu-immediately-on-auto-complete t)
(require 'auto-complete-clang)
(global-set-key (kbd "C-`") 'ac-complete-clang)
(setq ac-clang-flags
(mapcar (lambda (item)(concat "-I" item))
(split-string
"
/usr/include/c++/4.6
/usr/include/c++/4.6/i686-linux-gnu/.
/usr/include/c++/4.6/backward
/usr/lib/gcc/i686-linux-gnu/4.6.1/include
/usr/local/include
/usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed
/usr/include/i386-linux-gnu
/usr/include
"
)))
(defun check-for-Project-el ()
(let ((dirname))
(setq dirname (assoc-default 'project-root file-local-variables-alist))
(if (and (boundp 'dirname) dirname)
(setq project-file (expand-file-name "Project.el" dirname))
(if (and (boundp 'project-file)
(file-exists-p project-file))
(load-file project-file)))))
(add-hook 'find-file-hook 'check-for-Project-el)
;;; load clojure-mode to support coding for Clojure
(add-to-list 'load-path "~/.emacs.d/clojure")
(add-to-list 'load-path "~/.emacs.d/clojure-snippets-1.0.0")
(add-to-list 'load-path "~/.emacs.d/multiple-cursors-1.2.2") ;; for clj-refactor
(require 'clojure-mode)
(add-hook 'clojure-mode-hook #'enable-paredit-mode)
(require 'clj-refactor)
(add-hook 'clojure-mode-hook (lambda ()
(clj-refactor-mode 1)
;; keybinding setup here
(cljr-add-keybindings-with-prefix "C-c C-m")
(setq inferior-lisp-program "cljrepl")
))
(require 'clojure-snippets)
;; nREPL client
(require 'monroe)
(add-hook 'clojure-mode-hook 'clojure-enable-monroe)
(add-hook 'monroe-mode-hook #'enable-paredit-mode)
(define-key monroe-interaction-mode-map (kbd "C-c C-#") 'monroe-eval-region)
(defun run-monroe ()
"Opens up REPL in a window below"
(interactive)
(split-window-vertically)
(other-window 1)
(shrink-window 10)
(monroe monroe-default-host))
;;; Function to make inf-clojure work with clojure-mode 2.2.0
(defun clojure-mode-variables ()
(setq-local imenu-create-index-function
(lambda ()
(imenu--generic-function '((nil clojure-match-next-def 0)))))
(setq-local indent-tabs-mode nil)
(lisp-mode-variables nil)
(setq fill-paragraph-function 'clojure-fill-paragraph)
(setq adaptive-fill-function 'clojure-adaptive-fill-function)
(setq-local normal-auto-fill-function 'clojure-auto-fill-function)
(setq-local comment-start-skip
"\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *")
(setq-local lisp-indent-function 'clojure-indent-function)
(when (< emacs-major-version 24)
(setq-local forward-sexp-function 'clojure-forward-sexp))
(setq-local lisp-doc-string-elt-property 'clojure-doc-string-elt)
(setq-local inferior-lisp-program clojure-inf-lisp-command)
(setq-local parse-sexp-ignore-comments t)
(setq-local open-paren-in-column-0-is-defun-start nil)
(add-hook 'paredit-mode-hook
(lambda ()
(when (>= paredit-version 21)
(define-key clojure-mode-map "{" 'paredit-open-curly)
(define-key clojure-mode-map "}" 'paredit-close-curly)
(add-to-list 'paredit-space-for-delimiter-predicates
'clojure-space-for-delimiter-p)
(add-to-list 'paredit-space-for-delimiter-predicates
'clojure-no-space-after-tag)))))
(require 'inf-clojure)
(autoload 'inf-clojure "inf-clojure" "Run an inferior Clojure process" t)
(add-hook 'clojure-mode-hook 'inf-clojure-minor-mode)
(add-hook 'inf-clojure-mode-hook #'enable-paredit-mode)
(add-hook 'inf-clojure-mode-hook (lambda ()
(custom-set-variables '(inf-clojure-program "cljrepl repl"))
(push "build.gradle" inf-clojure-project-root-files)
))
(defun run-inf-clojure ()
"Opens up REPL in a window below"
(interactive)
(split-window-vertically)
(other-window 1)
(shrink-window 10)
(inf-clojure "cljrepl repl"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment