From 90b6af78feb803cd7ff59fb1a1c52bc60c8eab95 Mon Sep 17 00:00:00 2001 From: larstvei Date: Mon, 17 Nov 2014 01:10:38 +0100 Subject: [PATCH] November update. - Added possibility for private file. - Removed `try` and instead relay on the package Try. - Made `clear-shell` to a more general `clear-comint`. - Delay loading slime-helper until its needed. - Added `cycle-theme`, and changed default to leuven. --- README.md | 78 ++++++++++++++++++++++++++++++++++------------------- init.el | 73 +++++++++++++++++++++++++++++++++----------------- init.org | 80 ++++++++++++++++++++++++++++++++++++------------------- 3 files changed, 152 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index f2d0e8b..a3223a9 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,18 @@ tangled, and the tangled file is compiled." (add-hook 'after-save-hook 'tangle-init) ``` +I'd like to keep a few settings private, so we load a `private.el` if it +exists after the init-file has loaded. + +```emacs-lisp +(add-hook + 'after-init-hook + (lambda () + (let ((private-file (concat user-emacs-directory "private.el"))) + (when (file-exists-p private-file) + (load-file private-file))))) +``` + ## Package Managing extensions for Emacs is simplified using `package` which is @@ -223,7 +235,6 @@ configurations are also dependent on them). (when (and do-package-update-on-init (y-or-n-p "Update all packages?")) (package-refresh-contents) - (let* ((packages '(ac-geiser ; Auto-complete backend for geiser ac-slime ; An auto-complete source using slime completions @@ -252,7 +263,8 @@ configurations are also dependent on them). pretty-lambdada ; the word `lambda' as the Greek letter. slime ; Superior Lisp Interaction Mode for Emacs smex ; M-x interface with Ido-style fuzzy matching. - undo-tree)) ; Treat undo history as a tree + undo-tree ; Treat undo history as a tree + try)) ; Try out Emacs packages. ;; Fetch dependencies from all packages. (reqs (mapcar 'dependencies packages)) ;; Append these to the original list, and remove any duplicates. @@ -457,17 +469,30 @@ This makes `.md`-files open in `markdown-mode`. ## Visual -Change the color-theme to `monokai` (downloaded using `package`). +Change the color-theme to `leuven`. ```emacs-lisp -(load-theme 'monokai t) +(load-theme 'leuven t) +``` + +`leuven` is my preferred light theme, but `monokai` makes a very nice +dark theme. I want to be able to cycle between these. + +```emacs-lisp +(defun cycle-themes () + "Returns a function that lets you cycle your themes." + (lexical-let ((themes '#1=(leuven monokai . #1#))) + (lambda () + (interactive) + ;; Rotates the thme cycle and changes the current theme. + (load-theme (car (setq themes (cdr themes))) t)))) ``` Use the [Inconsolata](http://www.levien.com/type/myfonts/inconsolata.html) font if it's installed on the system. ```emacs-lisp -(when (member "Inconsolata-g" (font-family-list)) - (set-face-attribute 'default nil :font "Inconsolata-g-11")) +(when (member "Inconsolata" (font-family-list)) + (set-face-attribute 'default nil :font "Inconsolata-13")) ``` ## Ido @@ -661,7 +686,7 @@ I use `org-agenda` for appointments and such. ```emacs-lisp (setq org-agenda-start-on-weekday nil ; Show agenda from today. - org-agenda-files '("~/Dropbox/life.org") ; A list of agenda files. + org-agenda-files '("~/Dropbox/cal.org") ; A list of agenda files. org-agenda-default-appointment-duration 120) ; 2 hours appointments. ``` @@ -677,9 +702,11 @@ This is quite an ugly fix for allowing code markup for expressions like `"this string"`, because the quotation marks causes problems. ```emacs-lisp -(require 'org) -(setcar (nthcdr 2 org-emphasis-regexp-components) " \t\n,") -(custom-set-variables `(org-emphasis-alist ',org-emphasis-alist)) +;;(require 'org) +(eval-after-load "org" + '(progn + (setcar (nthcdr 2 org-emphasis-regexp-components) " \t\n,") + (custom-set-variables `(org-emphasis-alist ',org-emphasis-alist)))) ``` ## Interactive functions @@ -797,17 +824,6 @@ To tidy up a buffer we define this function borrowed from [simenheg](https://git (untabify beg (if (< end (point-max)) end (point-max))))) ``` -If you have a link to a raw `.el`-file, run `M-x try` and yank an URL -into the minibuffer, and the file will be evaluated. - -```emacs-lisp -(defun try (url) - "Takes an URL to a .el-file, and evaluates it." - (interactive (list (read-from-minibuffer "url: "))) - (with-current-buffer (url-retrieve-synchronously url) - (eval-region (search-forward-regexp "^$") (point-max)))) -``` - ## Advice An advice can be given to a function to make it behave differently. This @@ -892,7 +908,7 @@ does not remove anything. In Emacs removing stuff is less of a worry, since we can always undo! ```emacs-lisp -(defun clear-shell () +(defun clear-comint () "Runs `comint-truncate-buffer' with the `comint-buffer-maximum-size' set to zero." (interactive) @@ -905,7 +921,7 @@ global binding (because we want to be able to switch to a shell from any buffer), but the `clear-shell` should only affect `shell-mode`. ```emacs-lisp -(add-hook 'shell-mode-hook (lambda () (local-set-key (kbd "C-l") 'clear-shell))) +(add-hook 'comint-mode-hook (lambda () (local-set-key (kbd "C-l") 'clear-comint))) ``` ## Lisp @@ -951,8 +967,14 @@ and you can install Slime following the instructions from the site along with this snippet. ```emacs-lisp -(when (file-exists-p "~/.quicklisp/slime-helper.el") - (load (expand-file-name "~/.quicklisp/slime-helper.el"))) +(defun activate-slime-helper () + (when (file-exists-p "~/.quicklisp/slime-helper.elc") + (load (expand-file-name "~/.quicklisp/slime-helper.elc")) + (define-key slime-repl-mode-map (kbd "C-l") + 'slime-repl-clear-buffer)) + (remove-hook 'lisp-mode-hook #'activate-slime-helper)) + +(add-hook 'lisp-mode-hook #'activate-slime-helper) ``` We can specify what Common Lisp program Slime should use (I use SBCL). @@ -981,7 +1003,6 @@ More sensible `loop` indentation, borrowed from [simenheg](https://github.com/si ``` ```emacs-lisp -(define-key slime-repl-mode-map (kbd "C-l") 'slime-repl-clear-buffer) ``` ### Scheme @@ -1158,7 +1179,7 @@ Bindings for [expand-region](https://github.com/magnars/expand-region.el). ```emacs-lisp (define-key custom-bindings-map (kbd "C-'") 'er/expand-region) -(define-key custom-bindings-map (kbd "C-;") 'er/contract-region) +(define-key custom-bindings-map (kbd "C-\"") 'er/contract-region) ``` Bindings for [multiple-cursors](https://github.com/magnars/multiple-cursors.el). @@ -1212,8 +1233,11 @@ Bind some native Emacs functions. Bind the functions defined above. ```emacs-lisp +(define-key global-map (kbd "M-p") 'jump-to-previous-like-this) +(define-key global-map (kbd "M-n") 'jump-to-next-like-this) (define-key custom-bindings-map (kbd "M-,") 'jump-to-previous-like-this) (define-key custom-bindings-map (kbd "M-.") 'jump-to-next-like-this) +(define-key custom-bindings-map (kbd "C-c .") (cycle-themes)) (define-key custom-bindings-map (kbd "C-x k") 'kill-this-buffer-unless-scratch) (define-key custom-bindings-map (kbd "C-x t") 'toggle-shell) (define-key custom-bindings-map (kbd "C-c j") 'cycle-spacing-delete-newlines) diff --git a/init.el b/init.el index 3edcb3e..4e4cd94 100644 --- a/init.el +++ b/init.el @@ -21,6 +21,16 @@ tangled, and the tangled file is compiled." (add-hook 'after-save-hook 'tangle-init) +;; I'd like to keep a few settings private, so we load a =private.el= if it +;; exists after the init-file has loaded. + +(add-hook + 'after-init-hook + (lambda () + (let ((private-file (concat user-emacs-directory "private.el"))) + (when (file-exists-p private-file) + (load-file private-file))))) + ;; Package ;; Managing extensions for Emacs is simplified using =package= which is @@ -131,7 +141,6 @@ PACKAGE is installed and the current version is deleted." (when (and do-package-update-on-init (y-or-n-p "Update all packages?")) (package-refresh-contents) - (let* ((packages '(ac-geiser ; Auto-complete backend for geiser ac-slime ; An auto-complete source using slime completions @@ -160,7 +169,8 @@ PACKAGE is installed and the current version is deleted." pretty-lambdada ; the word `lambda' as the Greek letter. slime ; Superior Lisp Interaction Mode for Emacs smex ; M-x interface with Ido-style fuzzy matching. - undo-tree)) ; Treat undo history as a tree + undo-tree ; Treat undo history as a tree + try)) ; Try out Emacs packages. ;; Fetch dependencies from all packages. (reqs (mapcar 'dependencies packages)) ;; Append these to the original list, and remove any duplicates. @@ -336,14 +346,25 @@ PACKAGE is installed and the current version is deleted." ;; Visual -;; Change the color-theme to =monokai= (downloaded using =package=). +;; Change the color-theme to =leuven=. -(load-theme 'monokai t) +(load-theme 'leuven t) + +;; =leuven= is my preferred light theme, but =monokai= makes a very nice +;; dark theme. I want to be able to cycle between these. + +(defun cycle-themes () + "Returns a function that lets you cycle your themes." + (lexical-let ((themes '#1=(leuven monokai . #1#))) + (lambda () + (interactive) + ;; Rotates the thme cycle and changes the current theme. + (load-theme (car (setq themes (cdr themes))) t)))) ;; Use the [[http://www.levien.com/type/myfonts/inconsolata.html][Inconsolata]] font if it's installed on the system. -(when (member "Inconsolata-g" (font-family-list)) - (set-face-attribute 'default nil :font "Inconsolata-g-11")) +(when (member "Inconsolata" (font-family-list)) + (set-face-attribute 'default nil :font "Inconsolata-13")) ;; Ido @@ -509,7 +530,7 @@ the languages in ISPELL-LANGUAGES when invoked." ;; I use =org-agenda= for appointments and such. (setq org-agenda-start-on-weekday nil ; Show agenda from today. - org-agenda-files '("~/Dropbox/life.org") ; A list of agenda files. + org-agenda-files '("~/Dropbox/cal.org") ; A list of agenda files. org-agenda-default-appointment-duration 120) ; 2 hours appointments. ;; When editing org-files with source-blocks, we want the source blocks to @@ -521,9 +542,11 @@ the languages in ISPELL-LANGUAGES when invoked." ;; This is quite an ugly fix for allowing code markup for expressions like ;; ="this string"=, because the quotation marks causes problems. -(require 'org) -(setcar (nthcdr 2 org-emphasis-regexp-components) " \t\n,") -(custom-set-variables `(org-emphasis-alist ',org-emphasis-alist)) +;;(require 'org) +(eval-after-load "org" + '(progn + (setcar (nthcdr 2 org-emphasis-regexp-components) " \t\n,") + (custom-set-variables `(org-emphasis-alist ',org-emphasis-alist)))) ;; Interactive functions ;; <> @@ -627,15 +650,6 @@ the buffer is buried." (whitespace-cleanup) (untabify beg (if (< end (point-max)) end (point-max))))) -;; If you have a link to a raw =.el=-file, run =M-x try= and yank an URL -;; into the minibuffer, and the file will be evaluated. - -(defun try (url) - "Takes an URL to a .el-file, and evaluates it." - (interactive (list (read-from-minibuffer "url: "))) - (with-current-buffer (url-retrieve-synchronously url) - (eval-region (search-forward-regexp "^$") (point-max)))) - ;; Advice ;; An advice can be given to a function to make it behave differently. This @@ -707,7 +721,7 @@ the buffer is buried." ;; does not remove anything. In Emacs removing stuff is less of a worry, ;; since we can always undo! -(defun clear-shell () +(defun clear-comint () "Runs `comint-truncate-buffer' with the `comint-buffer-maximum-size' set to zero." (interactive) @@ -718,7 +732,7 @@ the buffer is buried." ;; global binding (because we want to be able to switch to a shell from any ;; buffer), but the =clear-shell= should only affect =shell-mode=. -(add-hook 'shell-mode-hook (lambda () (local-set-key (kbd "C-l") 'clear-shell))) +(add-hook 'comint-mode-hook (lambda () (local-set-key (kbd "C-l") 'clear-comint))) ;; Lisp @@ -756,8 +770,14 @@ the buffer is buried." ;; and you can install Slime following the instructions from the site along ;; with this snippet. -(when (file-exists-p "~/.quicklisp/slime-helper.el") - (load (expand-file-name "~/.quicklisp/slime-helper.el"))) +(defun activate-slime-helper () + (when (file-exists-p "~/.quicklisp/slime-helper.elc") + (load (expand-file-name "~/.quicklisp/slime-helper.elc")) + (define-key slime-repl-mode-map (kbd "C-l") + 'slime-repl-clear-buffer)) + (remove-hook 'lisp-mode-hook #'activate-slime-helper)) + +(add-hook 'lisp-mode-hook #'activate-slime-helper) ;; We can specify what Common Lisp program Slime should use (I use SBCL). @@ -778,7 +798,7 @@ the buffer is buried." lisp-simple-loop-indentation 2 lisp-loop-keyword-indentation 6) -(define-key slime-repl-mode-map (kbd "C-l") 'slime-repl-clear-buffer) + ;; Scheme @@ -925,7 +945,7 @@ math-block around the region." ;; Bindings for [[https://github.com/magnars/expand-region.el][expand-region]]. (define-key custom-bindings-map (kbd "C-'") 'er/expand-region) -(define-key custom-bindings-map (kbd "C-;") 'er/contract-region) +(define-key custom-bindings-map (kbd "C-\"") 'er/contract-region) ;; Bindings for [[https://github.com/magnars/multiple-cursors.el][multiple-cursors]]. @@ -963,8 +983,11 @@ math-block around the region." ;; Bind the functions defined [[sec:defuns][above]]. +(define-key global-map (kbd "M-p") 'jump-to-previous-like-this) +(define-key global-map (kbd "M-n") 'jump-to-next-like-this) (define-key custom-bindings-map (kbd "M-,") 'jump-to-previous-like-this) (define-key custom-bindings-map (kbd "M-.") 'jump-to-next-like-this) +(define-key custom-bindings-map (kbd "C-c .") (cycle-themes)) (define-key custom-bindings-map (kbd "C-x k") 'kill-this-buffer-unless-scratch) (define-key custom-bindings-map (kbd "C-x t") 'toggle-shell) (define-key custom-bindings-map (kbd "C-c j") 'cycle-spacing-delete-newlines) diff --git a/init.org b/init.org index 1f60c2a..05fa2e5 100644 --- a/init.org +++ b/init.org @@ -67,6 +67,18 @@ (add-hook 'after-save-hook 'tangle-init) #+END_SRC + I'd like to keep a few settings private, so we load a =private.el= if it + exists after the init-file has loaded. + + #+BEGIN_SRC emacs-lisp + (add-hook + 'after-init-hook + (lambda () + (let ((private-file (concat user-emacs-directory "private.el"))) + (when (file-exists-p private-file) + (load-file private-file))))) + #+END_SRC + ** Package Managing extensions for Emacs is simplified using =package= which is @@ -192,7 +204,6 @@ (when (and do-package-update-on-init (y-or-n-p "Update all packages?")) (package-refresh-contents) - (let* ((packages '(ac-geiser ; Auto-complete backend for geiser ac-slime ; An auto-complete source using slime completions @@ -221,7 +232,8 @@ pretty-lambdada ; the word `lambda' as the Greek letter. slime ; Superior Lisp Interaction Mode for Emacs smex ; M-x interface with Ido-style fuzzy matching. - undo-tree)) ; Treat undo history as a tree + undo-tree ; Treat undo history as a tree + try)) ; Try out Emacs packages. ;; Fetch dependencies from all packages. (reqs (mapcar 'dependencies packages)) ;; Append these to the original list, and remove any duplicates. @@ -428,17 +440,31 @@ ** Visual - Change the color-theme to =monokai= (downloaded using =package=). + Change the color-theme to =leuven=. #+BEGIN_SRC emacs-lisp - (load-theme 'monokai t) + (load-theme 'leuven t) + #+END_SRC + + =leuven= is my preferred light theme, but =monokai= makes a very nice + dark theme. I want to be able to cycle between these. + + #+BEGIN_SRC emacs-lisp + (defun cycle-themes () + "Returns a function that lets you cycle your themes." + (lexical-let ((themes '#1=(leuven monokai . #1#))) + (lambda () + (interactive) + ;; Rotates the thme cycle and changes the current theme. + (load-theme (car (setq themes (cdr themes))) t)))) + #+END_SRC Use the [[http://www.levien.com/type/myfonts/inconsolata.html][Inconsolata]] font if it's installed on the system. #+BEGIN_SRC emacs-lisp - (when (member "Inconsolata-g" (font-family-list)) - (set-face-attribute 'default nil :font "Inconsolata-g-11")) + (when (member "Inconsolata" (font-family-list)) + (set-face-attribute 'default nil :font "Inconsolata-13")) #+END_SRC @@ -666,7 +692,7 @@ #+BEGIN_SRC emacs-lisp (setq org-agenda-start-on-weekday nil ; Show agenda from today. - org-agenda-files '("~/Dropbox/life.org") ; A list of agenda files. + org-agenda-files '("~/Dropbox/cal.org") ; A list of agenda files. org-agenda-default-appointment-duration 120) ; 2 hours appointments. #+END_SRC @@ -683,9 +709,11 @@ ="this string"=, because the quotation marks causes problems. #+BEGIN_SRC emacs-lisp - (require 'org) - (setcar (nthcdr 2 org-emphasis-regexp-components) " \t\n,") - (custom-set-variables `(org-emphasis-alist ',org-emphasis-alist)) + ;;(require 'org) + (eval-after-load "org" + '(progn + (setcar (nthcdr 2 org-emphasis-regexp-components) " \t\n,") + (custom-set-variables `(org-emphasis-alist ',org-emphasis-alist)))) #+END_SRC ** Interactive functions @@ -802,17 +830,6 @@ (untabify beg (if (< end (point-max)) end (point-max))))) #+END_SRC - If you have a link to a raw =.el=-file, run =M-x try= and yank an URL - into the minibuffer, and the file will be evaluated. - - #+BEGIN_SRC emacs-lisp - (defun try (url) - "Takes an URL to a .el-file, and evaluates it." - (interactive (list (read-from-minibuffer "url: "))) - (with-current-buffer (url-retrieve-synchronously url) - (eval-region (search-forward-regexp "^$") (point-max)))) - #+END_SRC - ** Advice An advice can be given to a function to make it behave differently. This @@ -896,7 +913,7 @@ since we can always undo! #+BEGIN_SRC emacs-lisp - (defun clear-shell () + (defun clear-comint () "Runs `comint-truncate-buffer' with the `comint-buffer-maximum-size' set to zero." (interactive) @@ -909,7 +926,7 @@ buffer), but the =clear-shell= should only affect =shell-mode=. #+BEGIN_SRC emacs-lisp - (add-hook 'shell-mode-hook (lambda () (local-set-key (kbd "C-l") 'clear-shell))) + (add-hook 'comint-mode-hook (lambda () (local-set-key (kbd "C-l") 'clear-comint))) #+END_SRC ** Lisp @@ -955,8 +972,14 @@ with this snippet. #+BEGIN_SRC emacs-lisp - (when (file-exists-p "~/.quicklisp/slime-helper.el") - (load (expand-file-name "~/.quicklisp/slime-helper.el"))) + (defun activate-slime-helper () + (when (file-exists-p "~/.quicklisp/slime-helper.elc") + (load (expand-file-name "~/.quicklisp/slime-helper.elc")) + (define-key slime-repl-mode-map (kbd "C-l") + 'slime-repl-clear-buffer)) + (remove-hook 'lisp-mode-hook #'activate-slime-helper)) + + (add-hook 'lisp-mode-hook #'activate-slime-helper) #+END_SRC We can specify what Common Lisp program Slime should use (I use SBCL). @@ -985,7 +1008,7 @@ #+END_SRC #+BEGIN_SRC emacs-lisp - (define-key slime-repl-mode-map (kbd "C-l") 'slime-repl-clear-buffer) + #+END_SRC *** Scheme @@ -1174,7 +1197,7 @@ #+BEGIN_SRC emacs-lisp (define-key custom-bindings-map (kbd "C-'") 'er/expand-region) - (define-key custom-bindings-map (kbd "C-;") 'er/contract-region) + (define-key custom-bindings-map (kbd "C-\"") 'er/contract-region) #+END_SRC Bindings for [[https://github.com/magnars/multiple-cursors.el][multiple-cursors]]. @@ -1228,8 +1251,11 @@ Bind the functions defined [[sec:defuns][above]]. #+BEGIN_SRC emacs-lisp + (define-key global-map (kbd "M-p") 'jump-to-previous-like-this) + (define-key global-map (kbd "M-n") 'jump-to-next-like-this) (define-key custom-bindings-map (kbd "M-,") 'jump-to-previous-like-this) (define-key custom-bindings-map (kbd "M-.") 'jump-to-next-like-this) + (define-key custom-bindings-map (kbd "C-c .") (cycle-themes)) (define-key custom-bindings-map (kbd "C-x k") 'kill-this-buffer-unless-scratch) (define-key custom-bindings-map (kbd "C-x t") 'toggle-shell) (define-key custom-bindings-map (kbd "C-c j") 'cycle-spacing-delete-newlines)