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.

153 lines
6.0 KiB

13 years ago
14 years ago
13 years ago
13 years ago
  1. ;;; prelude-core.el --- Emacs Prelude: Core Prelude functions.
  2. ;;
  3. ;; Copyright © 2011-2020 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. ;; Here are the definitions of most of the general-purpose functions and
  10. ;; commands added by Prelude. Some modules define additional module-specific
  11. ;; functions and commands.
  12. ;;
  13. ;; Note that many of the original core Prelude commands were extracted to the
  14. ;; crux package (Prelude installs it automatically). Prelude's auto-save
  15. ;; functionality was extracted to the super-save package.
  16. ;;; License:
  17. ;; This program is free software; you can redistribute it and/or
  18. ;; modify it under the terms of the GNU General Public License
  19. ;; as published by the Free Software Foundation; either version 3
  20. ;; of the License, or (at your option) any later version.
  21. ;;
  22. ;; This program is distributed in the hope that it will be useful,
  23. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. ;; GNU General Public License for more details.
  26. ;;
  27. ;; You should have received a copy of the GNU General Public License
  28. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  29. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  30. ;; Boston, MA 02110-1301, USA.
  31. ;;; Code:
  32. (require 'cl-lib)
  33. (defun prelude-buffer-mode (buffer-or-name)
  34. "Retrieve the `major-mode' of BUFFER-OR-NAME."
  35. (with-current-buffer buffer-or-name
  36. major-mode))
  37. (defun prelude-search (query-url prompt)
  38. "Open the search url constructed with the QUERY-URL.
  39. PROMPT sets the `read-string prompt."
  40. (browse-url
  41. (concat query-url
  42. (url-hexify-string
  43. (if mark-active
  44. (buffer-substring (region-beginning) (region-end))
  45. (read-string prompt))))))
  46. (defmacro prelude-install-search-engine (search-engine-name search-engine-url search-engine-prompt)
  47. "Given some information regarding a search engine, install the interactive command to search through them"
  48. `(defun ,(intern (format "prelude-%s" search-engine-name)) ()
  49. ,(format "Search %s with a query or region if any." search-engine-name)
  50. (interactive)
  51. (prelude-search ,search-engine-url ,search-engine-prompt)))
  52. (prelude-install-search-engine "google" "http://www.google.com/search?q=" "Google: ")
  53. (prelude-install-search-engine "youtube" "http://www.youtube.com/results?search_query=" "Search YouTube: ")
  54. (prelude-install-search-engine "github" "https://github.com/search?q=" "Search GitHub: ")
  55. (prelude-install-search-engine "duckduckgo" "https://duckduckgo.com/?t=lm&q=" "Search DuckDuckGo: ")
  56. (defun prelude-recompile-init ()
  57. "Byte-compile all your dotfiles again."
  58. (interactive)
  59. (byte-recompile-directory prelude-dir 0))
  60. (defvar prelude-tips
  61. '("Press <C-c o> to open a file with external program."
  62. "Press <C-c p f> to navigate a project's files with ido."
  63. "Press <s-r> to open a recently visited file."
  64. "Press <C-c p s g> to run grep on a project."
  65. "Press <C-c p p> to switch between projects."
  66. "Press <C-=> to expand the selected region."
  67. "Press <C-c g> to search in Google."
  68. "Press <C-c G> to search in GitHub."
  69. "Press <C-c y> to search in YouTube."
  70. "Press <C-c U> to search in DuckDuckGo."
  71. "Press <C-c r> to rename the current buffer and the file it's visiting if any."
  72. "Press <C-c t> to open a terminal in Emacs."
  73. "Press <C-c k> to kill all the buffers, but the active one."
  74. "Press <C-x g> to run magit-status."
  75. "Press <C-c D> to delete the current file and buffer."
  76. "Press <C-c s> to swap two windows."
  77. "Press <S-RET> or <M-o> to open a line beneath the current one."
  78. "Press <s-o> to open a line above the current one."
  79. "Press <C-c C-z> in a Elisp buffer to launch an interactive Elisp shell."
  80. "Press <C-Backspace> to kill a line backwards."
  81. "Press <C-S-Backspace> or <s-k> to kill the whole line."
  82. "Press <s-j> or <C-^> to join lines."
  83. "Press <s-.> or <C-c v> to jump to the start of a word in any visible window."
  84. "Press <f12> to toggle the menu bar."
  85. "Explore the Tools->Prelude menu to find out about some of Prelude extensions to Emacs."
  86. "Access the official Emacs manual by pressing <C-h r>."))
  87. (defun prelude-tip-of-the-day ()
  88. "Display a random entry from `prelude-tips'."
  89. (interactive)
  90. (when (and prelude-tips (not (window-minibuffer-p)))
  91. ;; pick a new random seed
  92. (random t)
  93. (message
  94. (concat "Prelude tip: " (nth (random (length prelude-tips)) prelude-tips)))))
  95. (defun prelude-eval-after-init (form)
  96. "Add `(lambda () FORM)' to `after-init-hook'.
  97. If Emacs has already finished initialization, also eval FORM immediately."
  98. (let ((func (list 'lambda nil form)))
  99. (add-hook 'after-init-hook func)
  100. (when after-init-time
  101. (eval form))))
  102. (require 'epl)
  103. (defun prelude-update ()
  104. "Update Prelude to its latest version."
  105. (interactive)
  106. (when (y-or-n-p "Do you want to update Prelude? ")
  107. (message "Updating installed packages...")
  108. (epl-upgrade)
  109. (message "Updating Prelude...")
  110. (cd prelude-dir)
  111. (shell-command "git pull")
  112. (prelude-recompile-init)
  113. (message "Update finished. Restart Emacs to complete the process.")))
  114. (defun prelude-update-packages (&optional arg)
  115. "Update Prelude's packages.
  116. This includes package installed via `prelude-require-package'.
  117. With a prefix ARG updates all installed packages."
  118. (interactive "P")
  119. (when (y-or-n-p "Do you want to update Prelude's packages? ")
  120. (if arg
  121. (epl-upgrade)
  122. (epl-upgrade (cl-remove-if-not (lambda (p) (memq (epl-package-name p) prelude-packages))
  123. (epl-installed-packages))))
  124. (message "Update finished. Restart Emacs to complete the process.")))
  125. (defun prelude-wrap-with (s)
  126. "Create a wrapper function for smartparens using S."
  127. `(lambda (&optional arg)
  128. (interactive "P")
  129. (sp-wrap-with-pair ,s)))
  130. (provide 'prelude-core)
  131. ;;; prelude-core.el ends here