;;; prelude-core.el --- Emacs Prelude: Core Prelude functions. ;; ;; Copyright © 2011-2018 Bozhidar Batsov ;; ;; Author: Bozhidar Batsov ;; URL: https://github.com/bbatsov/prelude ;; Version: 1.0.0 ;; Keywords: convenience ;; This file is not part of GNU Emacs. ;;; Commentary: ;; Here are the definitions of most of the functions added by Prelude. ;;; 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: (require 'thingatpt) (require 'dash) (require 'ov) (defun prelude-buffer-mode (buffer-or-name) "Retrieve the `major-mode' of BUFFER-OR-NAME." (with-current-buffer buffer-or-name major-mode)) (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: ") (defun prelude-todo-ov-evaporate (_ov _after _beg _end &optional _length) (let ((inhibit-modification-hooks t)) (if _after (ov-reset _ov)))) (defun prelude-annotate-todo () "Put fringe marker on TODO: lines in the current buffer." (interactive) (ov-set (format "[[:space:]]*%s+[[:space:]]*TODO:" comment-start) 'before-string (propertize (format "A") 'display '(left-fringe right-triangle)) 'modification-hooks '(prelude-todo-ov-evaporate))) (defun prelude-recompile-init () "Byte-compile all your dotfiles again." (interactive) (byte-recompile-directory prelude-dir 0)) (defvar prelude-tips '("Press to open a file with external program." "Press to navigate a project's files with ido." "Press to open a recently visited file." "Press to run grep on a project." "Press to switch between projects." "Press to expand the selected region." "Press to search in Google." "Press to search in GitHub." "Press to search in YouTube." "Press to search in DuckDuckGo." "Press to rename the current buffer and the file it's visiting if any." "Press to open a terminal in Emacs." "Press to kill all the buffers, but the active one." "Press to run magit-status." "Press to delete the current file and buffer." "Press to swap two windows." "Press or to open a line beneath the current one." "Press to open a line above the current one." "Press in a Elisp buffer to launch an interactive Elisp shell." "Press to kill a line backwards." "Press or to kill the whole line." "Press or to join lines." "Press or to jump to the start of a word in any visible window." "Press to toggle fullscreen mode." "Press to toggle the menu bar." "Explore the Tools->Prelude menu to find out about some of Prelude extensions to Emacs." "Access the official Emacs manual by pressing ." "Visit the EmacsWiki at http://emacswiki.org to find out even more about Emacs.")) (defun prelude-tip-of-the-day () "Display a random entry from `prelude-tips'." (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))))) (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) (defun prelude-update () "Update Prelude to its latest version." (interactive) (when (y-or-n-p "Do you want to update Prelude? ") (message "Updating installed packages...") (epl-upgrade) (message "Updating Prelude...") (cd prelude-dir) (shell-command "git pull") (prelude-recompile-init) (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) (epl-upgrade (-filter (lambda (p) (memq (epl-package-name p) prelude-packages)) (epl-installed-packages)))) (message "Update finished. Restart Emacs to complete the process."))) ;;; Emacs in OSX already has fullscreen support ;;; Emacs has a similar built-in command in 24.4 (defun prelude-fullscreen () "Make Emacs window fullscreen. This follows freedesktop standards, should work in X servers." (interactive) (if (eq window-system 'x) (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_FULLSCREEN" 0)) (error "Only X server is supported"))) (defun prelude-wrap-with (s) "Create a wrapper function for smartparens using S." `(lambda (&optional arg) (interactive "P") (sp-wrap-with-pair ,s))) (provide 'prelude-core) ;;; prelude-core.el ends here