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.

149 lines
6.0 KiB

  1. ;;; prelude-mode.el --- Emacs Prelude: minor mode
  2. ;;
  3. ;; Copyright © 2011-2018 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. ;; A minor mode defining a local keymap, plus a menu.
  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. (require 'easymenu)
  29. (require 'imenu-anywhere)
  30. (require 'crux)
  31. (defvar prelude-mode-map
  32. (let ((map (make-sparse-keymap)))
  33. (define-key map (kbd "C-c o") 'crux-open-with)
  34. (define-key map (kbd "C-c g") 'prelude-google)
  35. (define-key map (kbd "C-c G") 'prelude-github)
  36. (define-key map (kbd "C-c y") 'prelude-youtube)
  37. (define-key map (kbd "C-c U") 'prelude-duckduckgo)
  38. ;; mimic popular IDEs binding, note that it doesn't work in a terminal session
  39. (define-key map (kbd "C-a") 'crux-move-beginning-of-line)
  40. (define-key map [(shift return)] 'crux-smart-open-line)
  41. (define-key map (kbd "M-o") 'crux-smart-open-line)
  42. (define-key map [(control shift return)] 'crux-smart-open-line-above)
  43. (define-key map [(control shift up)] 'move-text-up)
  44. (define-key map [(control shift down)] 'move-text-down)
  45. (define-key map [(meta shift up)] 'move-text-up)
  46. (define-key map [(meta shift down)] 'move-text-down)
  47. (define-key map (kbd "C-c n") 'crux-cleanup-buffer-or-region)
  48. (define-key map (kbd "C-c f") 'crux-recentf-ido-find-file)
  49. (define-key map (kbd "C-M-z") 'crux-indent-defun)
  50. (define-key map (kbd "C-c u") 'crux-view-url)
  51. (define-key map (kbd "C-c e") 'crux-eval-and-replace)
  52. (define-key map (kbd "C-c s") 'crux-swap-windows)
  53. (define-key map (kbd "C-c D") 'crux-delete-file-and-buffer)
  54. (define-key map (kbd "C-c d") 'crux-duplicate-current-line-or-region)
  55. (define-key map (kbd "C-c M-d") 'crux-duplicate-and-comment-current-line-or-region)
  56. (define-key map (kbd "C-c r") 'crux-rename-buffer-and-file)
  57. (define-key map (kbd "C-c t") 'crux-visit-term-buffer)
  58. (define-key map (kbd "C-c k") 'crux-kill-other-buffers)
  59. (define-key map (kbd "C-c TAB") 'crux-indent-rigidly-and-copy-to-clipboard)
  60. (define-key map (kbd "C-c I") 'crux-find-user-init-file)
  61. (define-key map (kbd "C-c S") 'crux-find-shell-init-file)
  62. (define-key map (kbd "C-c i") 'imenu-anywhere)
  63. ;; extra prefix for projectile
  64. (define-key map (kbd "s-p") 'projectile-command-map)
  65. ;; make some use of the Super key
  66. (define-key map (kbd "s-g") 'god-local-mode)
  67. (define-key map (kbd "s-r") 'crux-recentf-ido-find-file)
  68. (define-key map (kbd "s-j") 'crux-top-join-line)
  69. (define-key map (kbd "s-k") 'crux-kill-whole-line)
  70. (define-key map (kbd "s-m m") 'magit-status)
  71. (define-key map (kbd "s-m l") 'magit-log)
  72. (define-key map (kbd "s-m f") 'magit-log-buffer-file)
  73. (define-key map (kbd "s-m b") 'magit-blame)
  74. (define-key map (kbd "s-o") 'crux-smart-open-line-above)
  75. map)
  76. "Keymap for Prelude mode.")
  77. (defun prelude-mode-add-menu ()
  78. "Add a menu entry for `prelude-mode' under Tools."
  79. (easy-menu-add-item nil '("Tools")
  80. '("Prelude"
  81. ("Files"
  82. ["Open with..." crux-open-with]
  83. ["Delete file and buffer" crux-delete-file-and-buffer]
  84. ["Rename buffer and file" crux-rename-buffer-and-file])
  85. ("Buffers"
  86. ["Clean up buffer or region" crux-cleanup-buffer-or-region]
  87. ["Kill other buffers" crux-kill-other-buffers])
  88. ("Editing"
  89. ["Insert empty line" prelude-insert-empty-line]
  90. ["Move line up" prelude-move-line-up]
  91. ["Move line down" prelude-move-line-down]
  92. ["Duplicate line or region" prelude-duplicate-current-line-or-region]
  93. ["Indent rigidly and copy to clipboard" crux-indent-rigidly-and-copy-to-clipboard]
  94. ["Insert date" crux-insert-date]
  95. ["Eval and replace" crux-eval-and-replace]
  96. )
  97. ("Windows"
  98. ["Swap windows" crux-swap-windows])
  99. ("General"
  100. ["Visit term buffer" crux-visit-term-buffer]
  101. ["Search in Google" prelude-google]
  102. ["View URL" crux-view-url]))
  103. "Search Files (Grep)...")
  104. (easy-menu-add-item nil '("Tools") '("--") "Search Files (Grep)..."))
  105. (defun prelude-mode-remove-menu ()
  106. "Remove `prelude-mode' menu entry."
  107. (easy-menu-remove-item nil '("Tools") "Prelude")
  108. (easy-menu-remove-item nil '("Tools") "--"))
  109. ;; define minor mode
  110. (define-minor-mode prelude-mode
  111. "Minor mode to consolidate Emacs Prelude extensions.
  112. \\{prelude-mode-map}"
  113. :lighter " Pre"
  114. :keymap prelude-mode-map
  115. (if prelude-mode
  116. ;; on start
  117. (prelude-mode-add-menu)
  118. ;; on stop
  119. (prelude-mode-remove-menu)))
  120. (define-globalized-minor-mode prelude-global-mode prelude-mode prelude-on)
  121. (defun prelude-on ()
  122. "Turn on `prelude-mode'."
  123. (prelude-mode +1))
  124. (defun prelude-off ()
  125. "Turn off `prelude-mode'."
  126. (prelude-mode -1))
  127. (provide 'prelude-mode)
  128. ;;; prelude-mode.el ends here