refactored prog-mode related config into a separate module
This commit is contained in:
parent
78b726d49b
commit
2018709128
3 changed files with 114 additions and 72 deletions
1
init.el
1
init.el
|
@ -67,6 +67,7 @@ by Prelude.")
|
|||
(require 'prelude-global-keybindings)
|
||||
|
||||
;; programming & markup languages support
|
||||
(require 'prelude-programming)
|
||||
(require 'prelude-c)
|
||||
(require 'prelude-clojure)
|
||||
(require 'prelude-coffee)
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
(require 'cl)
|
||||
(require 'thingatpt)
|
||||
(require 'imenu)
|
||||
|
||||
(defun prelude-add-subfolders-to-load-path (parent-dir)
|
||||
"Adds all first level `parent-dir' subdirs to the
|
||||
|
@ -244,63 +243,11 @@ there's a region, all lines that region covers will be duplicated."
|
|||
(cond ((search-forward "<?xml" nil t) (xml-mode))
|
||||
((search-forward "<html" nil t) (html-mode)))))
|
||||
|
||||
(defun prelude-ido-goto-symbol (&optional symbol-list)
|
||||
"Refresh imenu and jump to a place in the buffer using Ido."
|
||||
(interactive)
|
||||
(unless (featurep 'imenu)
|
||||
(require 'imenu nil t))
|
||||
(cond
|
||||
((not symbol-list)
|
||||
(let ((ido-mode ido-mode)
|
||||
(ido-enable-flex-matching
|
||||
(if (boundp 'ido-enable-flex-matching)
|
||||
ido-enable-flex-matching t))
|
||||
name-and-pos symbol-names position)
|
||||
(unless ido-mode
|
||||
(ido-mode 1)
|
||||
(setq ido-enable-flex-matching t))
|
||||
(while (progn
|
||||
(imenu--cleanup)
|
||||
(setq imenu--index-alist nil)
|
||||
(prelude-ido-goto-symbol (imenu--make-index-alist))
|
||||
(setq selected-symbol
|
||||
(ido-completing-read "Symbol? " symbol-names))
|
||||
(string= (car imenu--rescan-item) selected-symbol)))
|
||||
(unless (and (boundp 'mark-active) mark-active)
|
||||
(push-mark nil t nil))
|
||||
(setq position (cdr (assoc selected-symbol name-and-pos)))
|
||||
(cond
|
||||
((overlayp position)
|
||||
(goto-char (overlay-start position)))
|
||||
(t
|
||||
(goto-char position)))))
|
||||
((listp symbol-list)
|
||||
(dolist (symbol symbol-list)
|
||||
(let (name position)
|
||||
(cond
|
||||
((and (listp symbol) (imenu--subalist-p symbol))
|
||||
(prelude-ido-goto-symbol symbol))
|
||||
((listp symbol)
|
||||
(setq name (car symbol))
|
||||
(setq position (cdr symbol)))
|
||||
((stringp symbol)
|
||||
(setq name symbol)
|
||||
(setq position
|
||||
(get-text-property 1 'org-imenu-marker symbol))))
|
||||
(unless (or (null position) (null name)
|
||||
(string= (car imenu--rescan-item) name))
|
||||
(add-to-list 'symbol-names name)
|
||||
(add-to-list 'name-and-pos (cons name position))))))))
|
||||
|
||||
;; We have a number of turn-on-* functions since it's advised that lambda
|
||||
;; functions not go in hooks. Repeatedly evaluating an add-to-list with a
|
||||
;; hook value will repeatedly add it since there's no way to ensure
|
||||
;; that a lambda doesn't already exist in the list.
|
||||
|
||||
(defun prelude-local-comment-auto-fill ()
|
||||
(set (make-local-variable 'comment-auto-fill-only-comments) t)
|
||||
(auto-fill-mode t))
|
||||
|
||||
(defun prelude-turn-on-whitespace ()
|
||||
(whitespace-mode +1))
|
||||
|
||||
|
@ -313,25 +260,6 @@ there's a region, all lines that region covers will be duplicated."
|
|||
(defun prelude-turn-off-abbrev ()
|
||||
(abbrev-mode -1))
|
||||
|
||||
(defun prelude-add-watchwords ()
|
||||
(font-lock-add-keywords
|
||||
nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
|
||||
1 font-lock-warning-face t))))
|
||||
|
||||
(defun prelude-prog-mode-hook ()
|
||||
"Default coding hook, useful with any programming language."
|
||||
(flyspell-prog-mode)
|
||||
(prelude-local-comment-auto-fill)
|
||||
(prelude-turn-on-whitespace)
|
||||
(prelude-turn-on-abbrev)
|
||||
(prelude-add-watchwords)
|
||||
;; keep the whitespace decent all the time
|
||||
(add-hook 'before-save-hook 'whitespace-cleanup nil t))
|
||||
|
||||
;; in Emacs 24 programming major modes generally derive
|
||||
;; from a common mode named prog-mode
|
||||
(add-hook 'prog-mode-hook 'prelude-prog-mode-hook)
|
||||
|
||||
(defun prelude-untabify-buffer ()
|
||||
(interactive)
|
||||
(untabify (point-min) (point-max)))
|
||||
|
|
113
modules/prelude-programming.el
Normal file
113
modules/prelude-programming.el
Normal file
|
@ -0,0 +1,113 @@
|
|||
;;; prelude-programming.el --- Emacs Prelude: prog-mode configuration
|
||||
;;
|
||||
;; Copyright (c) 2011 Bozhidar Batsov
|
||||
;;
|
||||
;; Author: Bozhidar Batsov <bozhidar.batsov@gmail.com>
|
||||
;; URL: http://www.emacswiki.org/cgi-bin/wiki/Prelude
|
||||
;; Version: 1.0.0
|
||||
;; Keywords: convenience
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Some basic prog-mode configuration and programming related utilities.
|
||||
|
||||
;;; License:
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License
|
||||
;; as published by the Free Software Foundation; either version 3
|
||||
;; of the License, or (at your option) any later version.
|
||||
;;
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
;;
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
;; Boston, MA 02110-1301, USA.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'imenu)
|
||||
|
||||
(defun prelude-ido-goto-symbol (&optional symbol-list)
|
||||
"Refresh imenu and jump to a place in the buffer using Ido."
|
||||
(interactive)
|
||||
(unless (featurep 'imenu)
|
||||
(require 'imenu nil t))
|
||||
(cond
|
||||
((not symbol-list)
|
||||
(let ((ido-mode ido-mode)
|
||||
(ido-enable-flex-matching
|
||||
(if (boundp 'ido-enable-flex-matching)
|
||||
ido-enable-flex-matching t))
|
||||
name-and-pos symbol-names position)
|
||||
(unless ido-mode
|
||||
(ido-mode 1)
|
||||
(setq ido-enable-flex-matching t))
|
||||
(while (progn
|
||||
(imenu--cleanup)
|
||||
(setq imenu--index-alist nil)
|
||||
(prelude-ido-goto-symbol (imenu--make-index-alist))
|
||||
(setq selected-symbol
|
||||
(ido-completing-read "Symbol? " symbol-names))
|
||||
(string= (car imenu--rescan-item) selected-symbol)))
|
||||
(unless (and (boundp 'mark-active) mark-active)
|
||||
(push-mark nil t nil))
|
||||
(setq position (cdr (assoc selected-symbol name-and-pos)))
|
||||
(cond
|
||||
((overlayp position)
|
||||
(goto-char (overlay-start position)))
|
||||
(t
|
||||
(goto-char position)))))
|
||||
((listp symbol-list)
|
||||
(dolist (symbol symbol-list)
|
||||
(let (name position)
|
||||
(cond
|
||||
((and (listp symbol) (imenu--subalist-p symbol))
|
||||
(prelude-ido-goto-symbol symbol))
|
||||
((listp symbol)
|
||||
(setq name (car symbol))
|
||||
(setq position (cdr symbol)))
|
||||
((stringp symbol)
|
||||
(setq name symbol)
|
||||
(setq position
|
||||
(get-text-property 1 'org-imenu-marker symbol))))
|
||||
(unless (or (null position) (null name)
|
||||
(string= (car imenu--rescan-item) name))
|
||||
(add-to-list 'symbol-names name)
|
||||
(add-to-list 'name-and-pos (cons name position))))))))
|
||||
|
||||
(defun prelude-local-comment-auto-fill ()
|
||||
(set (make-local-variable 'comment-auto-fill-only-comments) t)
|
||||
(auto-fill-mode t))
|
||||
|
||||
(defun prelude-add-watchwords ()
|
||||
(font-lock-add-keywords
|
||||
nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
|
||||
1 font-lock-warning-face t))))
|
||||
|
||||
;; show the name of the current function definition in the modeline
|
||||
(require 'which-func)
|
||||
(which-func-mode 1)
|
||||
|
||||
(defun prelude-prog-mode-hook ()
|
||||
"Default coding hook, useful with any programming language."
|
||||
(flyspell-prog-mode)
|
||||
(prelude-local-comment-auto-fill)
|
||||
(prelude-turn-on-whitespace)
|
||||
(prelude-turn-on-abbrev)
|
||||
(prelude-add-watchwords)
|
||||
;; keep the whitespace decent all the time
|
||||
(add-hook 'before-save-hook 'whitespace-cleanup nil t))
|
||||
|
||||
;; in Emacs 24 programming major modes generally derive
|
||||
;; from a common mode named prog-mode
|
||||
(add-hook 'prog-mode-hook 'prelude-prog-mode-hook)
|
||||
|
||||
(provide 'prelude-programming)
|
||||
;;; prelude-programming.el ends here
|
Loading…
Reference in a new issue