Skip to content

Instantly share code, notes, and snippets.

@soegaard
Created December 3, 2019 19:18
Show Gist options
  • Save soegaard/942a3074513655292816e0b79c466620 to your computer and use it in GitHub Desktop.
Save soegaard/942a3074513655292816e0b79c466620 to your computer and use it in GitHub Desktop.
;;;
;;; General Editing
;;;
;; When a region is highlighted typed text should replace the selction.
(delete-selection-mode 1)
;; Bind cmd-z to undo.
(global-set-key (kbd "s-z") #'undo)
;; Bind cmd-w to kill-buffer (which closes the buffer)
(global-set-key (kbd "s-w") #'kill-buffer)
;; Make control-\ insert an λ
(defun insert-lambda ()
"Insert the character λ"
(interactive)
(insert-char ?\λ))
(global-set-key (kbd "s-\\") #'insert-lambda)
;; Show Paren mode - mathcing parenthesis
(show-paren-mode 1)
;;; The package math-symbol-lists contains all symbols defined in unicode-math.
(package-initialize)
(require 'math-symbol-lists)
(quail-define-package "math" "UTF-8" "Ω" t)
(quail-define-rules ; add whatever extra rules you want to define here...
("\\aa" "å")
("\\Aa" "Å")
("\\ae" "æ")
("\\Ae" "Æ")
("\\oe" "ø")
("\\Oe" "Ø"))
(mapc (lambda (x) (if (cddr x) (quail-defrule (cadr x) (car (cddr x)))))
(append math-symbol-list-basic math-symbol-list-extended))
;; Laptop: up-arrow key is broken, so we need an alternative.
(global-set-key (kbd "M-p") #'beginning-of-buffer)
(global-set-key (kbd "<f1>") #'delete-other-windows)
(global-set-key (kbd "<f2>") #'other-buffer)
(global-set-key (kbd "<f3>") #'switch-to-buffer)
(global-set-key (kbd "<f7>") #'tabbar-backward)
(global-set-key (kbd "<f8>") #'tabbar-forward)
;; Desktop:
(global-set-key (kbd "<f13>") #'delete-other-windows)
(global-set-key (kbd "<f14>") #'other-window)
(global-set-key (kbd "<f15>") #'split-window-below)
(global-set-key (kbd "<f16>") #'tabbar-backward)
(global-set-key (kbd "<f17>") #'tabbar-forward)
(global-set-key (kbd "<f18>") #'switch-to-buffer)
;;;
;;; File Extension -> Mode
;;;
(add-to-list 'auto-mode-alist '("\\.scrbl\\'" . racket-mode))
(add-to-list 'auto-mode-alist '("\\.mscrbl\\'" . racket-mode))
;;;
;;; Color Themes
;;;
;; The package solarized-theme provides solarized-dark and solarized-light
;; Use M-x load-theme to try thems interactively.
(add-to-list 'load-path "~/.emacs.d/lisp/")
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'solarized-light t)
;; make the fringe stand out from the background
;(setq solarized-distinct-fringe-background t)
;;;
;;; Packages
;;;
;; The Emacs package repository is called Melpa.
(require 'package) ;; You might already have this line
(setq package-check-signature nil)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/") t)
(package-initialize)
;; Installed Packages
;; racket-mode mode for editing Racket programs
;; tabbar tabs (like a browser) at the top of the screen to switch between buffers
;; solarized-theme nicer colors
;;;
;;; Tabbar
;;;
;; A bar (line) with tabs representing the open buffers.
(require 'tabbar)
(customize-set-variable 'tabbar-background-color "gray20")
(customize-set-variable 'tabbar-separator '(0.5))
(customize-set-variable 'tabbar-use-images nil)
(tabbar-mode 1)
;; My preferred keys
; note: s means super aka cmd (i.e. it does not mean shift)
(define-key global-map (kbd "s-{") 'tabbar-backward) ; shift cmd {
(define-key global-map (kbd "s-}") 'tabbar-forward) ; shift cmd }
;; Colors
(set-face-attribute 'tabbar-default nil
:background "gray20" :foreground
"gray60" :distant-foreground "gray50"
:family "Helvetica Neue" :box nil)
(set-face-attribute 'tabbar-unselected nil
:background "gray80" :foreground "black" :box nil)
(set-face-attribute 'tabbar-modified nil
:foreground "red4" :box nil
:inherit 'tabbar-unselected)
(set-face-attribute 'tabbar-selected nil
:background "#4090c0" :foreground "white" :box nil)
(set-face-attribute 'tabbar-selected-modified nil
:inherit 'tabbar-selected :foreground "GoldenRod2" :box nil)
(set-face-attribute 'tabbar-button nil
:box nil)
;; Use Powerline to make tabs look nicer
;; (this needs to run *after* the colors are set)
(require 'powerline)
(defvar my/tabbar-height 24) ; needs to be +6 (when font size is 18)
(defvar my/tabbar-left (powerline-wave-right 'tabbar-default nil my/tabbar-height))
(defvar my/tabbar-right (powerline-wave-left nil 'tabbar-default my/tabbar-height))
(defun my/tabbar-tab-label-function (tab)
(powerline-render (list my/tabbar-left (format " %s " (car tab)) my/tabbar-right)))
(setq tabbar-tab-label-function #'my/tabbar-tab-label-function)
;;;
;;; Key Bindings
;;;
;; For key bindings always use small named functions rather than lambda expressions.
(require 'racket-mode)
(defun my-racket-switch-from-repl-to-editor ()
"Switch from the Racket repl to the editor. Hide the repl."
(interactive)
(racket-repl-switch-to-edit)
(delete-other-windows))
(defun my-racket-switch-from-editor-to-repl ()
"Switch from the Racket (editor) buffer to the repl. Hide the editor."
(interactive)
(racket-repl)
(delete-other-windows))
(defun my-racket-repl-also-display-editor ()
"Display editor window owning repl"
(interactive)
(racket-repl-switch-to-edit))
(defun my-racket-run-from-editor ()
"Run program in editor buffer. Switch to repl."
(interactive)
(racket-run)
(other-window 1)) ; number of windows to skip
(defun my-racket-indent-whole-buffer ()
"Indent whole buffer"
(interactive)
(save-excursion
;; Use point-min and point-max to respect narrowing.
(indent-region (point-min) (point-max))))
;; Note: In keybinding s means cmd (super).
;; Use hooks to add key bindings to a particular mode only.
;; Hooks for racket related modes:
;; racket-mode-hook
;; racket-repl-mode-hook
;; racket-repl-mode-map
(add-hook 'racket-mode-hook
(lambda ()
(define-key racket-mode-map (kbd "M-<left>") #'backward-sexp)
(define-key racket-mode-map (kbd "M-<right>") #'forward-sexp)
(define-key racket-mode-map (kbd "s-r") #'my-racket-run-from-editor)
(define-key racket-mode-map (kbd "s-e") #'racket-repl)
(define-key racket-mode-map (kbd "s-d") #'my-racket-switch-from-editor-to-repl)
(define-key racket-mode-map (kbd "s-i") #'my-racket-indent-whole-buffer)
(define-key racket-mode-map (kbd "s-<left>") #'move-beginning-of-line)
(define-key racket-mode-map (kbd "s-<right>") #'move-end-of-line)
(define-key racket-mode-map (kbd "s-<down>") #'scroll-up-command)
(show-paren-mode)))
(add-hook 'racket-repl-mode-hook
(lambda ()
(define-key racket-repl-mode-map (kbd "s-e") #'my-racket-switch-from-repl-to-editor)
(define-key racket-repl-mode-map (kbd "s-d") #'delete-other-windows)))
(add-hook 'racket-repl-mode-hook #'racket-unicode-input-method-enable)
(add-hook 'racket-mode-hook #'racket-unicode-input-method-enable)
;; Use global-set-key to add global key bindings
; (global-set-key (quote [f1]] (quote help-for-help))
;;;
;;; Customization
;;;
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
'(column-number-mode t)
'(custom-safe-themes
(quote
("0598c6a29e13e7112cfbc2f523e31927ab7dce56ebb2016b567e1eff6dc1fd4f" "d91ef4e714f05fff2070da7ca452980999f5361209e679ee988e3c432df24347" default)))
'(default-input-method "math")
'(line-number-mode nil)
'(package-selected-packages
(quote
(math-symbol-lists markdown-preview-mode markdown-mode powerline solarized-theme tabbar racket-mode)))
'(racket-program "/Applications/Racket v7.4/bin/racket")
'(racket-raco-program " /Applications/Racket v7.3/bin/raco")
'(show-paren-mode t)
'(tabbar-background-color "gray20")
'(tabbar-mode t nil (tabbar))
'(tabbar-separator (quote (0.5)))
'(tabbar-use-images nil)
'(tool-bar-mode nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(put 'narrow-to-region 'disabled nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment