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.

133 lines
5.6 KiB

5 years ago
  1. ;;; prelude-mode.el --- Emacs Prelude: minor mode
  2. ;;
  3. ;; Copyright © 2011-2022 Bozhidar Batsov
  4. ;;
  5. ;; Author: Bozhidar Batsov <bozhidar@batsov.com>
  6. ;; URL: https://github.com/bbatsov/prelude
  7. ;; This file is not part of GNU Emacs.
  8. ;;; Commentary:
  9. ;; A minor mode defining a local keymap, plus a menu.
  10. ;;; License:
  11. ;; This program is free software; you can redistribute it and/or
  12. ;; modify it under the terms of the GNU General Public License
  13. ;; as published by the Free Software Foundation; either version 3
  14. ;; of the License, or (at your option) any later version.
  15. ;;
  16. ;; This program is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; GNU General Public License for more details.
  20. ;;
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  23. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  24. ;; Boston, MA 02110-1301, USA.
  25. ;;; Code:
  26. (require 'easymenu)
  27. (require 'imenu-anywhere)
  28. (require 'crux)
  29. (defvar prelude-mode-map
  30. (let ((map (make-sparse-keymap)))
  31. (define-key map (kbd "C-c o") 'crux-open-with)
  32. (define-key map (kbd "C-c C-/ g") 'prelude-google)
  33. (define-key map (kbd "C-c C-/ h") 'prelude-github)
  34. (define-key map (kbd "C-c C-/ y") 'prelude-youtube)
  35. (define-key map (kbd "C-c C-/ d") 'prelude-duckduckgo)
  36. ;; mimic popular IDEs binding, note that it doesn't work in a terminal session
  37. (define-key map (kbd "C-a") 'crux-move-beginning-of-line)
  38. (define-key map [(shift return)] 'crux-smart-open-line)
  39. (define-key map (kbd "M-o") 'crux-smart-open-line)
  40. (define-key map [(control shift return)] 'crux-smart-open-line-above)
  41. (define-key map [(control shift up)] 'move-text-up)
  42. (define-key map [(control shift down)] 'move-text-down)
  43. (define-key map [(meta shift up)] 'move-text-up)
  44. (define-key map [(meta shift down)] 'move-text-down)
  45. (define-key map (kbd "C-c n") 'crux-cleanup-buffer-or-region)
  46. (define-key map (kbd "C-c f") 'crux-recentf-find-file)
  47. (define-key map (kbd "C-M-z") 'crux-indent-defun)
  48. (define-key map (kbd "C-c u") 'crux-view-url)
  49. (define-key map (kbd "C-c e") 'crux-eval-and-replace)
  50. (define-key map (kbd "C-c s") 'crux-swap-windows)
  51. (define-key map (kbd "C-c D") 'crux-delete-file-and-buffer)
  52. (define-key map (kbd "C-c d") 'crux-duplicate-current-line-or-region)
  53. (define-key map (kbd "C-c M-d") 'crux-duplicate-and-comment-current-line-or-region)
  54. (define-key map (kbd "C-c r") 'crux-rename-buffer-and-file)
  55. (define-key map (kbd "C-c t") 'crux-visit-term-buffer)
  56. (define-key map (kbd "C-c k") 'crux-kill-other-buffers)
  57. (define-key map (kbd "C-c TAB") 'crux-indent-rigidly-and-copy-to-clipboard)
  58. (define-key map (kbd "C-c I") 'crux-find-user-init-file)
  59. (define-key map (kbd "C-c S") 'crux-find-shell-init-file)
  60. (define-key map (kbd "C-c i") 'imenu-anywhere)
  61. ;; extra prefix for projectile
  62. (when prelude-super-keybindings
  63. (define-key map (kbd "s-p") 'projectile-command-map))
  64. (define-key map (kbd "C-c p") 'projectile-command-map)
  65. ;; make some use of the Super key
  66. (when prelude-super-keybindings
  67. ;; crux
  68. (define-key map (kbd "s-r") 'crux-recentf-find-file)
  69. (define-key map (kbd "s-j") 'crux-top-join-line)
  70. (define-key map (kbd "s-k") 'crux-kill-whole-line)
  71. (define-key map (kbd "s-o") 'crux-smart-open-line-above)
  72. ;; magit
  73. (define-key map (kbd "s-m m") 'magit-status)
  74. (define-key map (kbd "s-m j") 'magit-dispatch)
  75. (define-key map (kbd "s-m k") 'magit-file-dispatch)
  76. (define-key map (kbd "s-m l") 'magit-log-buffer-file)
  77. (define-key map (kbd "s-m b") 'magit-blame)
  78. ;; misc
  79. (define-key map (kbd "s-/") 'hippie-expand))
  80. (easy-menu-define prelude-mode-menu map
  81. "Prelude's menu."
  82. '("Prelude"
  83. ("Files"
  84. ["Open with..." crux-open-with]
  85. ["Re-open as root" crux-reopen-as-root]
  86. ["Delete file and buffer" crux-delete-file-and-buffer]
  87. ["Rename buffer and file" crux-rename-buffer-and-file]
  88. ["Find init file" crux-find-user-init-file]
  89. ["Find custom file" crux-find-user-custom-file]
  90. ["Find shell config file" crux-find-shell-init-file])
  91. ("Buffers"
  92. ["Clean up buffer or region" crux-cleanup-buffer-or-region]
  93. ["Kill other buffers" crux-kill-other-buffers])
  94. ("Editing"
  95. ["Go to beginning of line" crux-move-beginning-of-line]
  96. ["Kill line" crux-smart-kill-line]
  97. ["Kill whole line" crux-kill-whole-line]
  98. ["Insert empty line below" crux-smart-open-line]
  99. ["Insert empty line above" crux-smart-open-line-above]
  100. ["Move up" move-text-up]
  101. ["Move down" move-text-down]
  102. ["Duplicate line or region" crux-duplicate-current-line-or-region]
  103. ["Indent rigidly and copy to clipboard" crux-indent-rigidly-and-copy-to-clipboard]
  104. ["Indent defun" crux-indent-defun]
  105. ["Insert date" crux-insert-date]
  106. ["Eval and replace" crux-eval-and-replace])
  107. ("Windows"
  108. ["Swap windows" crux-swap-windows])
  109. ("General"
  110. ["Visit term buffer" crux-visit-term-buffer]
  111. ["Search in Google" prelude-google]
  112. ["View URL" crux-view-url])))
  113. map)
  114. "Keymap for Prelude mode.")
  115. ;; define minor mode
  116. (define-minor-mode prelude-mode
  117. "Minor mode to consolidate Emacs Prelude extensions.
  118. \\{prelude-mode-map}"
  119. :lighter " Pre"
  120. :keymap prelude-mode-map
  121. :global t)
  122. (provide 'prelude-mode)
  123. ;;; prelude-mode.el ends here