This files contains some global keybindings and various settings for Emacs.
Paredit tries to balance your parenthesis in your lispy languages. It is pretty much amazing.
(use-package paredit
:defer t
:init
(defun paredit-barf-all-the-way-backward ()
(interactive)
(paredit-split-sexp)
(paredit-backward-down)
(paredit-splice-sexp))
(defun paredit-barf-all-the-way-forward ()
(interactive)
(paredit-split-sexp)
(paredit-forward-down)
(paredit-splice-sexp)
(if (eolp) (delete-horizontal-space)))
(defun paredit-slurp-all-the-way-backward ()
(interactive)
(catch 'done
(while (not (bobp))
(save-excursion
(paredit-backward-up)
(if (eq (char-before) ?\()
(throw 'done t)))
(paredit-backward-slurp-sexp))))
(defun paredit-slurp-all-the-way-forward ()
(interactive)
(catch 'done
(while (not (eobp))
(save-excursion
(paredit-forward-up)
(if (eq (char-after) ?\))
(throw 'done t)))
(paredit-forward-slurp-sexp)))))
I have some specific keybindings for my paredit code
(defun elisp/turn-on-paredit ()
(autoload 'enable-paredit-mode "paredit"
"Turn on pseudo-structural editing of Lisp code."
t)
(define-key emacs-lisp-mode-map (kbd "C-c 0") 'paredit-forward-slurp-sexp)
(define-key emacs-lisp-mode-map (kbd "C-c 9") 'paredit-backward-slurp-sexp)
(define-key emacs-lisp-mode-map (kbd "C-c ]") 'paredit-forward-barf-sexp)
(define-key emacs-lisp-mode-map (kbd "C-c [") 'paredit-backward-barf-sexp)
(define-key emacs-lisp-mode-map (kbd "C-c )") 'paredit-slurp-all-the-way-forward)
(define-key emacs-lisp-mode-map (kbd "C-c }") 'paredit-barf-all-the-way-forward)
(define-key emacs-lisp-mode-map (kbd "C-c (") 'paredit-slurp-all-the-way-backward)
(define-key emacs-lisp-mode-map (kbd "C-c {") 'paredit-barf-all-the-way-backward)
(evil-define-key 'normal evil-dvorak-mode-map (kbd "k") 'paredit-kill)
;;(evil-paredit-mode +1)
)
(defun scheme/turn-on-paredit ()
(autoload 'enable-paredit-mode "paredit"
"Turn on pseudo-structural editing of Lisp code."
t)
(define-key scheme-mode-map (kbd "C-c 0") 'paredit-forward-slurp-sexp)
(define-key scheme-mode-map (kbd "C-c 9") 'paredit-backward-slurp-sexp)
(define-key scheme-mode-map (kbd "C-c ]") 'paredit-forward-barf-sexp)
(define-key scheme-mode-map (kbd "C-c [") 'paredit-backward-barf-sexp)
(define-key scheme-mode-map (kbd "C-c )") 'paredit-slurp-all-the-way-forward)
(define-key scheme-mode-map (kbd "C-c }") 'paredit-barf-all-the-way-forward)
(define-key scheme-mode-map (kbd "C-c (") 'paredit-slurp-all-the-way-backward)
(define-key scheme-mode-map (kbd "C-c {") 'paredit-barf-all-the-way-backward)
(evil-define-key 'normal evil-dvorak-mode-map (kbd "k") 'paredit-kill)
;;(evil-paredit-mode +1)
)
Evil-paredit is not available on melpa. I should probably fix this.
(require 'evil-paredit)
(add-hook 'emacs-lisp-mode-hook '(lambda ()
(rainbow-delimiters-mode 1)
;; You want to enable evil-paredit mode for evil, because it's SOOO helpful.
(evil-paredit-mode 1)
(elisp/turn-on-paredit)
;; make >= look like ≥
(push '(">=" . ?≥) prettify-symbols-alist)
(push '("<=" . ?≤) prettify-symbols-alist)
(push '("float-pi" . ?π) prettify-symbols-alist)
(push '("float-pi" . ?e) prettify-symbols-alist)))
(autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
(add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-mode-hook #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook 'evil-paredit-mode)
(add-hook 'scheme-mode-hook 'scheme/turn-on-paredit)
(defun scheme/turn-on-paredit ()
(autoload 'enable-paredit-mode "paredit"
"Turn on pseudo-structural editing of Lisp code."
t)
(define-key scheme-mode-map (kbd "C-c 0") 'paredit-forward-slurp-sexp)
(define-key scheme-mode-map (kbd "C-c 9") 'paredit-backward-slurp-sexp)
(define-key scheme-mode-map (kbd "C-c ]") 'paredit-forward-barf-sexp)
(define-key scheme-mode-map (kbd "C-c [") 'paredit-backward-barf-sexp)
(define-key scheme-mode-map (kbd "C-c )") 'paredit-slurp-all-the-way-forward)
(define-key scheme-mode-map (kbd "C-c }") 'paredit-barf-all-the-way-forward)
(define-key scheme-mode-map (kbd "C-c (") 'paredit-slurp-all-the-way-backward)
(define-key scheme-mode-map (kbd "C-c {") 'paredit-barf-all-the-way-backward)
(evil-define-key 'normal evil-dvorak-mode-map (kbd "k") 'paredit-kill)
(paredit-mode +1))
(add-hook 'scheme-mode-hook '(lambda ()
(rainbow-delimiters-mode 1)
;; You want to enable evil-paredit mode for evil, because it's SOOO helpful.
(evil-paredit-mode 1)
(scheme/turn-on-paredit)
;; make >= look like ≥
(push '(">=" . ?≥) prettify-symbols-alist)
(push '("<=" . ?≤) prettify-symbols-alist)))
Install geiser mode for guile code
(use-package geiser
:defer t
:config
(setq geiser-active-implementations '(guile)))
#+BEGIN_SRC emacs-lisp (use-package scheme-mode :mode ("\\.sxml\\'" . scheme-mode)) #+END_SRC
This mode really confuses me. I'm turning it off.
emacs regexp are cumbersome "\b" in most regexp engines means word end but when one is programming in emacs-lisp you have to write "\\b" easy escape is light prettify-mode and changes \\ --> one highlighted \
(use-package easy-escape
:config (add-hook 'emacs-lisp-mode-hook #'easy-escape-minor-mode)
:diminish easy-escape-minor-mode)
(defun getBufferStringFromWordAtPoint ()
"This function gets the buffer string from the word at point"
(interactive)
(print
(buffer-substring (progn
(backward-word)
(point))
(progn
(forward-word)
(point)))))
font-lock-constant-face is defined , but for whatever reason, I can't seem to use it in Emacs lisp mode. Why?
(defface font-lock-green-color
'((t (:foreground "#00ff00")))
"For boolean values")
(defun highlightBoolsElisp ()
"This highlights the boolean values in elisp."
(interactive)
(font-lock-add-keywords nil
'(("\\<t\\>" 1 'font-lock-green-color prepend)
("\\<nil\\>" 1 'font-lock-green-color prepend))))
;;(add-hook 'emacs-lisp-mode-hook #'highlightBoolsElisp)
(provide 'init-lisp)
#+BEGIN_SRC emacs-lisp (use-package auto-compile ) (auto-compile-on-save-mode 1) (auto-compile-on-load-mode 1) #+END_SRC
Load .el if newer than corresponding .elc #+BEGIN_SRC emacs-lisp (setq load-prefer-newer t) #+END_SRC
I can't figure out how to get parinfer to work...It makes writing lispy code hard and not fun.
(use-package parinfer
:bind
(("C-," . parinfer-toggle-mode))
:init
(progn
(setq parinfer-extensions
'(defaults ; should be included.
pretty-parens ; different paren styles for different modes.
evil ; If you use Evil.
;;lispy ; If you use Lispy. With this extension, you should install Lispy and do not enable lispy-mode directly.
paredit ; Introduce some paredit commands.
smart-tab ; C-b & C-f jump positions and smart shift with tab & S-tab.
smart-yank)) ; Yank behavior depend on mode.
(add-hook 'clojure-mode-hook #'parinfer-mode)
(add-hook 'emacs-lisp-mode-hook #'parinfer-mode)
(add-hook 'common-lisp-mode-hook #'parinfer-mode)
(add-hook 'scheme-mode-hook #'parinfer-mode)
(add-hook 'lisp-mode-hook #'parinfer-mode)))
(defun my/reeval-defun-at-point ()
"This reevaluates the defun at point."
(interactive)
(let (current-pos-of-point)
(setq current-pos-of-point (point))
(search-backward-regexp "^.*(defun\\|^(defun")
(evil-jump-item)
(eval-last-sexp)
(goto-char current-pos-of-point)))
(define-key emacs-lisp-mode-map (kbd "C-x e") #'my/reeval-defun-at-point)
#+END_SRC
* provide this file
:ID: a9e16be2-e2dd-4825-95c1-f86efdbadd74
:END:
#+BEGIN_SRC emacs-lisp
(provide 'init-lisp)