Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.5 KiB

13 years ago
13 years ago
  1. ;;; prelude-programming.el --- Emacs Prelude: prog-mode configuration
  2. ;;
  3. ;; Copyright © 2011-2013 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar@batsov.com>
  6. ;; URL: https://github.com/bbatsov/prelude
  7. ;; Version: 1.0.0
  8. ;; Keywords: convenience
  9. ;; This file is not part of GNU Emacs.
  10. ;;; Commentary:
  11. ;; Some basic prog-mode configuration and programming related utilities.
  12. ;;; License:
  13. ;; This program is free software; you can redistribute it and/or
  14. ;; modify it under the terms of the GNU General Public License
  15. ;; as published by the Free Software Foundation; either version 3
  16. ;; of the License, or (at your option) any later version.
  17. ;;
  18. ;; This program is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;;
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  25. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  26. ;; Boston, MA 02110-1301, USA.
  27. ;;; Code:
  28. (prelude-ensure-module-deps '(guru-mode))
  29. (defun prelude-ido-goto-symbol (&optional symbol-list)
  30. "Refresh imenu and jump to a place in the buffer using Ido."
  31. (interactive)
  32. (unless (featurep 'imenu)
  33. (require 'imenu nil t))
  34. (cond
  35. ((not symbol-list)
  36. (let ((ido-mode ido-mode)
  37. (ido-enable-flex-matching
  38. (if (boundp 'ido-enable-flex-matching)
  39. ido-enable-flex-matching t))
  40. name-and-pos symbol-names position)
  41. (unless ido-mode
  42. (ido-mode 1)
  43. (setq ido-enable-flex-matching t))
  44. (while (progn
  45. (imenu--cleanup)
  46. (setq imenu--index-alist nil)
  47. (prelude-ido-goto-symbol (imenu--make-index-alist))
  48. (setq selected-symbol
  49. (ido-completing-read "Symbol? " symbol-names))
  50. (string= (car imenu--rescan-item) selected-symbol)))
  51. (unless (and (boundp 'mark-active) mark-active)
  52. (push-mark nil t nil))
  53. (setq position (cdr (assoc selected-symbol name-and-pos)))
  54. (cond
  55. ((overlayp position)
  56. (goto-char (overlay-start position)))
  57. (t
  58. (goto-char position)))))
  59. ((listp symbol-list)
  60. (dolist (symbol symbol-list)
  61. (let (name position)
  62. (cond
  63. ((and (listp symbol) (imenu--subalist-p symbol))
  64. (prelude-ido-goto-symbol symbol))
  65. ((listp symbol)
  66. (setq name (car symbol))
  67. (setq position (cdr symbol)))
  68. ((stringp symbol)
  69. (setq name symbol)
  70. (setq position
  71. (get-text-property 1 'org-imenu-marker symbol))))
  72. (unless (or (null position) (null name)
  73. (string= (car imenu--rescan-item) name))
  74. (add-to-list 'symbol-names (substring-no-properties name))
  75. (add-to-list 'name-and-pos (cons (substring-no-properties name) position))))))))
  76. ;; add a shortcut for prelude-ido-goto-symbol
  77. (eval-after-load 'prelude-mode
  78. '(define-key prelude-mode-map (kbd "C-c i") 'prelude-ido-goto-symbol))
  79. (defun prelude-local-comment-auto-fill ()
  80. (set (make-local-variable 'comment-auto-fill-only-comments) t))
  81. (defun prelude-add-watchwords ()
  82. (font-lock-add-keywords
  83. nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
  84. 1 font-lock-warning-face t))))
  85. ;; show the name of the current function definition in the modeline
  86. (require 'which-func)
  87. (setq which-func-modes t)
  88. (which-function-mode 1)
  89. ;; in Emacs 24 programming major modes generally derive from a common
  90. ;; mode named prog-mode; for others, we'll arrange for our mode
  91. ;; defaults function to run prelude-prog-mode-hook directly. To
  92. ;; augment and/or counteract these defaults your own function
  93. ;; to prelude-prog-mode-hook, using:
  94. ;;
  95. ;; (add-hook 'prelude-prog-mode-hook 'my-prog-mode-defaults t)
  96. ;;
  97. ;; (the final optional t sets the *append* argument)
  98. (defun prelude-prog-mode-defaults ()
  99. "Default coding hook, useful with any programming language."
  100. (when (and (executable-find ispell-program-name)
  101. prelude-flyspell)
  102. (flyspell-prog-mode))
  103. (when prelude-guru
  104. (guru-mode +1))
  105. (prelude-enable-whitespace)
  106. (flycheck-mode +1)
  107. (prelude-local-comment-auto-fill)
  108. (prelude-add-watchwords))
  109. (setq prelude-prog-mode-hook 'prelude-prog-mode-defaults)
  110. (add-hook 'prog-mode-hook (lambda ()
  111. (run-hooks 'prelude-prog-mode-hook)))
  112. (provide 'prelude-programming)
  113. ;;; prelude-programming.el ends here