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.

178 lines
6.8 KiB

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