2012-12-15 22:07:25 +02:00
|
|
|
;;; prelude-programming.el --- Emacs Prelude: prog-mode configuration
|
|
|
|
;;
|
2013-01-02 13:13:59 +02:00
|
|
|
;; Copyright © 2011-2013 Bozhidar Batsov
|
2012-12-15 22:07:25 +02:00
|
|
|
;;
|
|
|
|
;; Author: Bozhidar Batsov <bozhidar@batsov.com>
|
|
|
|
;; URL: http://batsov.com/emacs-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:
|
|
|
|
|
2013-01-02 14:29:14 +02:00
|
|
|
(prelude-ensure-module-deps '(guru-mode))
|
|
|
|
|
2012-12-15 22:07:25 +02:00
|
|
|
(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))
|
2012-12-23 09:54:46 +02:00
|
|
|
(add-to-list 'symbol-names (substring-no-properties name))
|
|
|
|
(add-to-list 'name-and-pos (cons (substring-no-properties name) position))))))))
|
2012-12-15 22:07:25 +02:00
|
|
|
|
|
|
|
;; add a shortcut for prelude-ido-goto-symbol
|
|
|
|
(eval-after-load 'prelude-mode
|
|
|
|
'(define-key prelude-mode-map (kbd "C-c i") 'prelude-ido-goto-symbol))
|
|
|
|
|
|
|
|
(defun prelude-local-comment-auto-fill ()
|
|
|
|
(set (make-local-variable 'comment-auto-fill-only-comments) 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)
|
2013-01-02 14:34:09 +02:00
|
|
|
(setq which-func-modes t)
|
2012-12-15 22:07:25 +02:00
|
|
|
(which-function-mode 1)
|
|
|
|
|
|
|
|
;; in Emacs 24 programming major modes generally derive from a common
|
|
|
|
;; mode named prog-mode; for others, we'll arrange for our mode
|
|
|
|
;; defaults function to run prelude-prog-mode-hook directly. To
|
|
|
|
;; augment and/or counteract these defaults your own function
|
|
|
|
;; to prelude-prog-mode-hook, using:
|
|
|
|
;;
|
|
|
|
;; (add-hook 'prelude-prog-mode-hook 'my-prog-mode-defaults t)
|
|
|
|
;;
|
|
|
|
;; (the final optional t sets the *append* argument)
|
|
|
|
|
|
|
|
(defun prelude-prog-mode-defaults ()
|
|
|
|
"Default coding hook, useful with any programming language."
|
|
|
|
(when (and (executable-find ispell-program-name)
|
|
|
|
prelude-flyspell)
|
|
|
|
(flyspell-prog-mode))
|
|
|
|
(when prelude-guru
|
|
|
|
(guru-mode +1))
|
2013-01-05 10:38:12 +02:00
|
|
|
(prelude-enable-whitespace)
|
2013-01-03 23:08:32 +02:00
|
|
|
(flycheck-mode +1)
|
2012-12-15 22:07:25 +02:00
|
|
|
(prelude-local-comment-auto-fill)
|
2012-12-23 11:24:55 +02:00
|
|
|
(prelude-add-watchwords))
|
2012-12-15 22:07:25 +02:00
|
|
|
|
|
|
|
(setq prelude-prog-mode-hook 'prelude-prog-mode-defaults)
|
|
|
|
|
|
|
|
(add-hook 'prog-mode-hook (lambda ()
|
|
|
|
(run-hooks 'prelude-prog-mode-hook)))
|
|
|
|
|
|
|
|
(provide 'prelude-programming)
|
|
|
|
;;; prelude-programming.el ends here
|