Skip to content

Instantly share code, notes, and snippets.

@afeinberg
Last active August 29, 2015 13:57
Show Gist options
  • Save afeinberg/9879927 to your computer and use it in GitHub Desktop.
Save afeinberg/9879927 to your computer and use it in GitHub Desktop.
;; based on something I found online, but no longer have original link to.
(defvar *per-dir-hook-alist*
'(("/home/alex/dev/project" project-c-mode-hook)))
(defun af-directory-based-c-hook ()
(make-local-variable 'c-recognize-knr-p)
(make-local-variable 'c-enable-xemacs-performance-kludge-p)
(make-local-variable 'c-comment-only-line-offset)
(make-local-variable 'c-hanging-braces-alist)
(make-local-variable 'c-hanging-colons-alist)
(make-local-variable 'c-hanging-semi&comma-criteria)
(make-local-variable 'c-indent-comments-syntactically-p)
(make-local-variable 'comment-column)
(make-local-variable 'c-indent-comment-alist)
(make-local-variable 'c-cleanup-list)
(make-local-variable 'tab-width)
(make-local-variable 'indent-tabs-mode)
(make-local-variable 'fill-column)
(make-local-variable 'tab-width)
(make-local-variable 'c-tab-always-indent)
(make-local-variable 'c-auto-hungry-initial-state)
(make-local-variable 'c-default-style)
(make-local-variable 'c-indent-level)
(make-local-variable 'c-auto-hungry-initial-state)
(make-local-variable 'c-block-comment-prefix)
(make-local-variable 'c-basic-offset)
(make-local-variable 'c-offsets-alist)
(make-local-variable 'c-tab-always-indent)
(make-local-variable 'fill-column)
(dolist (dir-mode-pair *per-dir-hook-alist*)
(let ((dir-name (concat (first dir-mode-pair) ".*"))
(mode-is (car (last dir-mode-pair)))
(match-dir-based (string-match
(concat (first dir-mode-pair) ".*")
(buffer-file-name))))
(if (and (numberp match-dir-based)
(>= match-dir-based 0))
(funcall mode-is))))
(message ">>> done af-directory-based-c-hook..."))
(add-to-list 'auto-mode-alist '("/home/alex/dev/project/src/.*\\.h$" . c++-mode))
(defun project-c-mode-hook ()
(google-set-c-style)
(google-make-newline-indent)
(message ">>> done project-c-mode-hook"))
(add-hook 'c++-mode-hook 'af-directory-based-c-hook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment