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.

163 lines
6.3 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-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. ;; Here are the definitions of most of the functions added by Prelude.
  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 'thingatpt)
  29. (require 'cl-lib)
  30. (defun prelude-buffer-mode (buffer-or-name)
  31. "Retrieve the `major-mode' of BUFFER-OR-NAME."
  32. (with-current-buffer buffer-or-name
  33. major-mode))
  34. (defun prelude-search (query-url prompt)
  35. "Open the search url constructed with the QUERY-URL.
  36. PROMPT sets the `read-string prompt."
  37. (browse-url
  38. (concat query-url
  39. (url-hexify-string
  40. (if mark-active
  41. (buffer-substring (region-beginning) (region-end))
  42. (read-string prompt))))))
  43. (defmacro prelude-install-search-engine (search-engine-name search-engine-url search-engine-prompt)
  44. "Given some information regarding a search engine, install the interactive command to search through them"
  45. `(defun ,(intern (format "prelude-%s" search-engine-name)) ()
  46. ,(format "Search %s with a query or region if any." search-engine-name)
  47. (interactive)
  48. (prelude-search ,search-engine-url ,search-engine-prompt)))
  49. (prelude-install-search-engine "google" "http://www.google.com/search?q=" "Google: ")
  50. (prelude-install-search-engine "youtube" "http://www.youtube.com/results?search_query=" "Search YouTube: ")
  51. (prelude-install-search-engine "github" "https://github.com/search?q=" "Search GitHub: ")
  52. (prelude-install-search-engine "duckduckgo" "https://duckduckgo.com/?t=lm&q=" "Search DuckDuckGo: ")
  53. (defun prelude-recompile-init ()
  54. "Byte-compile all your dotfiles again."
  55. (interactive)
  56. (byte-recompile-directory prelude-dir 0))
  57. (defvar prelude-tips
  58. '("Press <C-c o> to open a file with external program."
  59. "Press <C-c p f> to navigate a project's files with ido."
  60. "Press <s-r> to open a recently visited file."
  61. "Press <C-c p s g> to run grep on a project."
  62. "Press <C-c p p> to switch between projects."
  63. "Press <C-=> to expand the selected region."
  64. "Press <C-c g> to search in Google."
  65. "Press <C-c G> to search in GitHub."
  66. "Press <C-c y> to search in YouTube."
  67. "Press <C-c U> to search in DuckDuckGo."
  68. "Press <C-c r> to rename the current buffer and the file it's visiting if any."
  69. "Press <C-c t> to open a terminal in Emacs."
  70. "Press <C-c k> to kill all the buffers, but the active one."
  71. "Press <C-x g> to run magit-status."
  72. "Press <C-c D> to delete the current file and buffer."
  73. "Press <C-c s> to swap two windows."
  74. "Press <S-RET> or <M-o> to open a line beneath the current one."
  75. "Press <s-o> to open a line above the current one."
  76. "Press <C-c C-z> in a Elisp buffer to launch an interactive Elisp shell."
  77. "Press <C-Backspace> to kill a line backwards."
  78. "Press <C-S-Backspace> or <s-k> to kill the whole line."
  79. "Press <s-j> or <C-^> to join lines."
  80. "Press <s-.> or <C-c j> to jump to the start of a word in any visible window."
  81. "Press <f11> to toggle fullscreen mode."
  82. "Press <f12> to toggle the menu bar."
  83. "Explore the Tools->Prelude menu to find out about some of Prelude extensions to Emacs."
  84. "Access the official Emacs manual by pressing <C-h r>."))
  85. (defun prelude-tip-of-the-day ()
  86. "Display a random entry from `prelude-tips'."
  87. (interactive)
  88. (when (and prelude-tips (not (window-minibuffer-p)))
  89. ;; pick a new random seed
  90. (random t)
  91. (message
  92. (concat "Prelude tip: " (nth (random (length prelude-tips)) prelude-tips)))))
  93. (defun prelude-eval-after-init (form)
  94. "Add `(lambda () FORM)' to `after-init-hook'.
  95. If Emacs has already finished initialization, also eval FORM immediately."
  96. (let ((func (list 'lambda nil form)))
  97. (add-hook 'after-init-hook func)
  98. (when after-init-time
  99. (eval form))))
  100. (require 'epl)
  101. (defun prelude-update ()
  102. "Update Prelude to its latest version."
  103. (interactive)
  104. (when (y-or-n-p "Do you want to update Prelude? ")
  105. (message "Updating installed packages...")
  106. (epl-upgrade)
  107. (message "Updating Prelude...")
  108. (cd prelude-dir)
  109. (shell-command "git pull")
  110. (prelude-recompile-init)
  111. (message "Update finished. Restart Emacs to complete the process.")))
  112. (defun prelude-update-packages (&optional arg)
  113. "Update Prelude's packages.
  114. This includes package installed via `prelude-require-package'.
  115. With a prefix ARG updates all installed packages."
  116. (interactive "P")
  117. (when (y-or-n-p "Do you want to update Prelude's packages? ")
  118. (if arg
  119. (epl-upgrade)
  120. (epl-upgrade (cl-remove-if-not (lambda (p) (memq (epl-package-name p) prelude-packages))
  121. (epl-installed-packages))))
  122. (message "Update finished. Restart Emacs to complete the process.")))
  123. ;;; Emacs in macOS already has fullscreen support
  124. ;;; Emacs has a similar built-in command in 24.4
  125. (defun prelude-fullscreen ()
  126. "Make Emacs window fullscreen.
  127. This follows freedesktop standards, should work in X servers."
  128. (interactive)
  129. (if (eq window-system 'x)
  130. (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
  131. '(2 "_NET_WM_STATE_FULLSCREEN" 0))
  132. (error "Only X server is supported")))
  133. (defun prelude-wrap-with (s)
  134. "Create a wrapper function for smartparens using S."
  135. `(lambda (&optional arg)
  136. (interactive "P")
  137. (sp-wrap-with-pair ,s)))
  138. (provide 'prelude-core)
  139. ;;; prelude-core.el ends here