emacs-prelude/core/prelude-core.el

154 lines
6 KiB
EmacsLisp
Raw Normal View History

2013-03-07 09:57:33 +02:00
;;; prelude-core.el --- Emacs Prelude: Core Prelude functions.
2011-10-08 23:05:06 +03:00
;;
2020-01-20 16:35:36 +02:00
;; Copyright © 2011-2020 Bozhidar Batsov
2011-10-08 23:05:06 +03:00
;;
;; Author: Bozhidar Batsov <bozhidar@batsov.com>
2013-03-07 09:57:33 +02:00
;; URL: https://github.com/bbatsov/prelude
2011-10-08 23:05:06 +03:00
;; This file is not part of GNU Emacs.
;;; Commentary:
2020-09-16 13:18:50 +03:00
;; Here are the definitions of most of the general-purpose functions and
;; commands added by Prelude. Some modules define additional module-specific
;; functions and commands.
;;
;; Note that many of the original core Prelude commands were extracted to the
;; crux package (Prelude installs it automatically). Prelude's auto-save
;; functionality was extracted to the super-save package.
2011-10-08 23:05:06 +03:00
;;; License:
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
2018-05-08 22:54:42 +03:00
(require 'cl-lib)
2011-10-08 23:05:06 +03:00
(defun prelude-buffer-mode (buffer-or-name)
2013-03-07 09:57:33 +02:00
"Retrieve the `major-mode' of BUFFER-OR-NAME."
2013-04-05 14:43:15 +03:00
(with-current-buffer buffer-or-name
major-mode))
2011-10-08 23:05:06 +03:00
(defun prelude-search (query-url prompt)
"Open the search url constructed with the QUERY-URL.
PROMPT sets the `read-string prompt."
(browse-url
(concat query-url
(url-hexify-string
(if mark-active
(buffer-substring (region-beginning) (region-end))
(read-string prompt))))))
(defmacro prelude-install-search-engine (search-engine-name search-engine-url search-engine-prompt)
"Given some information regarding a search engine, install the interactive command to search through them"
`(defun ,(intern (format "prelude-%s" search-engine-name)) ()
,(format "Search %s with a query or region if any." search-engine-name)
(interactive)
(prelude-search ,search-engine-url ,search-engine-prompt)))
(prelude-install-search-engine "google" "http://www.google.com/search?q=" "Google: ")
(prelude-install-search-engine "youtube" "http://www.youtube.com/results?search_query=" "Search YouTube: ")
(prelude-install-search-engine "github" "https://github.com/search?q=" "Search GitHub: ")
(prelude-install-search-engine "duckduckgo" "https://duckduckgo.com/?t=lm&q=" "Search DuckDuckGo: ")
2013-08-26 17:58:02 +03:00
2011-10-08 23:05:06 +03:00
(defun prelude-recompile-init ()
"Byte-compile all your dotfiles again."
(interactive)
2012-04-17 17:47:05 +03:00
(byte-recompile-directory prelude-dir 0))
2011-10-08 23:05:06 +03:00
2012-05-07 18:04:03 +03:00
(defvar prelude-tips
'("Press <C-c o> to open a file with external program."
2020-09-23 10:22:25 +03:00
"Press <C-c p f> to navigate a project's files."
"Press <s-r> to open a recently visited file."
"Press <C-c p s g> to run grep on a project."
"Press <C-c p p> to switch between projects."
"Press <C-=> to expand the selected region."
2020-12-10 21:01:13 +02:00
"Press <C-c C-/ g> to search in Google."
"Press <C-c C-/ h> to search in GitHub."
"Press <C-c C-/ y> to search in YouTube."
"Press <C-c C-/ d> to search in DuckDuckGo."
2014-05-31 20:11:42 +03:00
"Press <C-c r> to rename the current buffer and the file it's visiting if any."
2012-05-07 18:04:03 +03:00
"Press <C-c t> to open a terminal in Emacs."
2013-07-23 16:51:02 +03:00
"Press <C-c k> to kill all the buffers, but the active one."
"Press <C-x g> to run magit-status."
2013-07-23 16:51:02 +03:00
"Press <C-c D> to delete the current file and buffer."
"Press <C-c s> to swap two windows."
"Press <S-RET> or <M-o> to open a line beneath the current one."
2013-07-23 16:51:02 +03:00
"Press <s-o> to open a line above the current one."
"Press <C-c C-z> in a Elisp buffer to launch an interactive Elisp shell."
2013-07-26 17:54:20 +03:00
"Press <C-Backspace> to kill a line backwards."
"Press <C-S-Backspace> or <s-k> to kill the whole line."
"Press <s-j> or <C-^> to join lines."
2020-09-23 10:12:27 +03:00
"Press <s-.> or <C-c v> to jump to the start of a word in any visible window."
2013-07-26 17:54:20 +03:00
"Press <f12> to toggle the menu bar."
2020-09-23 10:22:25 +03:00
"Explore the Prelude menu to find out about some of Prelude extensions to Emacs."
2018-05-09 10:01:23 +03:00
"Access the official Emacs manual by pressing <C-h r>."))
2012-05-07 18:04:03 +03:00
(defun prelude-tip-of-the-day ()
2013-03-07 09:57:33 +02:00
"Display a random entry from `prelude-tips'."
2012-05-07 18:04:03 +03:00
(interactive)
(when (and prelude-tips (not (window-minibuffer-p)))
;; pick a new random seed
(random t)
(message
(concat "Prelude tip: " (nth (random (length prelude-tips)) prelude-tips)))))
2012-05-07 18:04:03 +03:00
(defun prelude-eval-after-init (form)
"Add `(lambda () FORM)' to `after-init-hook'.
If Emacs has already finished initialization, also eval FORM immediately."
(let ((func (list 'lambda nil form)))
(add-hook 'after-init-hook func)
(when after-init-time
(eval form))))
(require 'epl)
2013-03-11 20:13:06 +02:00
(defun prelude-update ()
"Update Prelude to its latest version."
(interactive)
2013-05-23 11:29:22 +03:00
(when (y-or-n-p "Do you want to update Prelude? ")
(message "Updating installed packages...")
(epl-upgrade)
2013-03-11 20:13:06 +02:00
(message "Updating Prelude...")
(cd prelude-dir)
(shell-command "git pull")
(prelude-recompile-init)
2013-03-11 20:13:06 +02:00
(message "Update finished. Restart Emacs to complete the process.")))
(defun prelude-update-packages (&optional arg)
"Update Prelude's packages.
This includes package installed via `prelude-require-package'.
With a prefix ARG updates all installed packages."
(interactive "P")
(when (y-or-n-p "Do you want to update Prelude's packages? ")
(if arg
(epl-upgrade)
2018-05-08 22:54:42 +03:00
(epl-upgrade (cl-remove-if-not (lambda (p) (memq (epl-package-name p) prelude-packages))
(epl-installed-packages))))
(message "Update finished. Restart Emacs to complete the process.")))
2013-12-07 09:14:44 +02:00
(defun prelude-wrap-with (s)
"Create a wrapper function for smartparens using S."
`(lambda (&optional arg)
(interactive "P")
(sp-wrap-with-pair ,s)))
2011-10-08 23:05:06 +03:00
(provide 'prelude-core)
;;; prelude-core.el ends here