Skip to content

Instantly share code, notes, and snippets.

@silvercircle
Created May 4, 2018 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silvercircle/66e76b5426c28640f164d43a5263d8b5 to your computer and use it in GitHub Desktop.
Save silvercircle/66e76b5426c28640f164d43a5263d8b5 to your computer and use it in GitHub Desktop.
My .emacs
"
This is my emacs configuration file. It's optimized to be used with emacs in
daemon mode, but should work without.
Tested and compatible with Emacs 25.3 and Emacs 26 on FreeBSD and several Linux
flavors. Note that display-line-numbers-mode REQUIRES Emacs 26+.
required elpa modules:
treemacs
sr-speedbar (inactive)
ido
company
web-mode
markdown-mode
markdown+-mode
vimish-fold
"
(package-initialize)
(when window-system (set-frame-size (selected-frame) 160 60))
"
set a default size for new frames
"
(add-hook 'before-make-frame-hook
#'(lambda ()
(add-to-list 'default-frame-alist '(left . 150))
(add-to-list 'default-frame-alist '(top . 20))
(add-to-list 'default-frame-alist '(height . 60))
(add-to-list 'default-frame-alist '(width . 166))))
(add-hook 'server-switch-hook
(lambda ()
;;this has become necessary to fight a strange bug I've seen
;;occasionally, which is probably related to some add-on. It simply
;;prevents the cursor from becoming invisible when whitespace mode
;;is enabled.
(custom-set-faces
'(cursor ((t (:background "yellow" :foreground "yellow")))))
(setq speedbar-use-images t)
(setq sr-speedbar-width 30)
(setq sr-speedbar-default-width 30)
(setq sr-speedbar-max-width 30)
(setq treemacs-width 30)
(when window-system
(setq sr-speedbar-width 37)
(setq sr-speedbar-default-width 37)
(setq sr-speedbar-max-width 37)
(setq treemacs-width 35)
(set-frame-size (selected-frame) 167 60))
;;(sr-speedbar-open)
;;make treemacs visible
(treemacs)
;;and unfocus it
(next-multiframe-window)))
;;(with-current-buffer sr-speedbar-buffer-name
;; (setq window-size-fixed 'width))))
(require 'ido)
(ido-mode t)
(global-unset-key (kbd "M-m"))
"
treemacs stuff
"
(use-package treemacs
:ensure t
:defer t
:init
(with-eval-after-load 'winum
(define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
;; (set-face-attribute 'hl-line nil :background "#333333")
:config
(progn
(setq treemacs-change-root-without-asking nil
treemacs-collapse-dirs (if (executable-find "python") 3 0)
treemacs-file-event-delay 5000
treemacs-follow-after-init t
treemacs-follow-recenter-distance 0.1
treemacs-goto-tag-strategy 'refetch-index
treemacs-indentation 2
treemacs-indentation-string " "
treemacs-is-never-other-window t
treemacs-never-persist nil
treemacs-no-png-images nil
treemacs-recenter-after-file-follow t
treemacs-recenter-after-tag-follow t
treemacs-show-hidden-files t
treemacs-silent-filewatch nil
treemacs-silent-refresh nil
treemacs-sorting 'alphabetic-desc
treemacs-tag-follow-cleanup t
treemacs-tag-follow-delay 1.5
treemacs-width 35)
(treemacs-follow-mode t)
(treemacs-filewatch-mode t)
(pcase (cons (not (null (executable-find "git")))
(not (null (executable-find "python3"))))
(`(t . t)
(treemacs-git-mode 'simple))
(`(t . _)
(treemacs-git-mode 'simple))))
:bind
(:map global-map
([f8] . treemacs-toggle)
("M-0" . treemacs-select-window)
("C-c 1" . treemacs-delete-other-windows)
("M-m ft" . treemacs-toggle)
("M-m fT" . treemacs)
("M-m fB" . treemacs-bookmark)
("M-m f C-t" . treemacs-find-file)
("M-m f M-t" . treemacs-find-tag)))
"
this is for sr-speedbar, it's inactive as I prefer treemacs
"
;;(use-package sr-speedbar
;; :bind (("C-x C-n" . sr-speedbar-toggle))
;; :ensure t
;; :defer t
;; :init
;; (setq sr-speedbar-right-side nil)
;; (setq speedbar-show-unknown-files t)
;; (setq sr-speedbar-width 30)
;; (setq sr-speedbar-default-width 30)
;; (setq sr-speedbar-max-width 30)
(setq treemacs-width 30)
(when window-system
(setq treemacs-width 35))
;; (setq sr-speedbar-width 40)
;; (setq sr-speedbar-default-width 40)
;; (setq sr-speedbar-max-width 40))
;; (setq speedbar-use-images t)
;;(treemacs)
;;(sr-speedbar-open)
;;(with-current-buffer sr-speedbar-buffer-name
;; (setq window-size-fixed 'width))
;;(next-multiframe-window)
;;(setq speedbar-initial-expansion-list-name "quick buffers")
;; )
;; use web-mode for most web editing, including html
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
;; text justification shortcuts
(global-unset-key (kbd "M-j"))
(global-set-key (kbd "C-e") 'ido-switch-buffer)
(global-set-key (kbd "M-j f") 'set-justification-full)
(global-set-key (kbd "M-j l") 'set-justification-left)
(global-set-key (kbd "M-j r") 'set-justification-right)
;; easy spell check
(global-set-key (kbd "<f12>") 'ispell-word)
(global-set-key (kbd "C-S-<f12>") 'flyspell-mode)
(global-set-key (kbd "C-<f12>") 'flyspell-buffer)
(global-set-key (kbd "C-M-<f12>") 'flyspell-check-previous-highlighted-word)
;;quickly toggle fill mode
(global-set-key (kbd "M-w") 'auto-fill-mode)
;; multiple cursors
(require 'multiple-cursors)
(global-set-key (kbd "M-j mc") 'mc/edit-lines)
(global-set-key (kbd "M-j mm") 'mc/mark-next-like-this)
;; company mode
(global-set-key (kbd "C-p") 'company-complete)
(add-hook 'after-init-hook
(lambda()
(global-company-mode)))
;; set up programming modes
(add-hook 'prog-mode-hook
(lambda()
;;(nlinum-mode) (obsolete with emacs 26)
;;requires emacs 26' native line number mode
(display-line-numbers-mode)
(electric-pair-mode)
(which-function-mode 1)
(setq tab-width 4)
(setq indent-tabs-mode nil)))
(add-hook 'text-mode-hook
(lambda()
(display-line-numbers-mode)))
(defun flyspell-check-next-highlighted-word ()
"Custom function to spell check next highlighted word"
(interactive)
(flyspell-goto-next-error)
(ispell-word))
(global-set-key (kbd "M-<f8>") 'flyspell-check-next-highlighted-word)
(defface message-double-quoted-text-face
'((t :foreground "cyan"
))
"Face for function parameters."
:group 'my-lang-mode )
(defface message-multiply-quoted-text-face
'((t :foreground "yellow"
))
"Face for function parameters."
:group 'my-lang-mode )
(defface message-signature-text-face
'((t :foreground "blue"
))
"Face for function parameters."
:group 'my-lang-mode )
(use-package all-the-icons-dired
;; M-x all-the-icons-install-fonts
:ensure t
:commands (all-the-icons-dired-mode))
(put 'dired-find-alternate-file 'disabled nil)
(setq-default bidi-display-reordering nil)
(setq nlinum-format "%5d \u2502 ")
(setq-default tab-width 4) ; or any other preferred value
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)
(setq-default indent-tabs-mode nil)
(setq-default python-indent 4)
;; this is automatically created by customize-group
(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-names-vector
["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#e090d7" "#8cc4ff" "#eeeeec"])
'(auto-save-default nil)
'(column-number-mode t)
'(cua-mode t nil (cua-base))
'(custom-enabled-themes (quote (tango-dark)))
'(custom-safe-themes
(quote
("3e65d4a1de31cdaa835602325bf9c521438aff8c3cb56f99ce8b2746fa30cecd" default)))
'(delete-selection-mode nil)
'(display-line-numbers nil)
'(display-line-numbers-grow-only nil)
'(display-line-numbers-widen t)
'(display-line-numbers-width 5)
'(display-time-mode t)
'(fancy-splash-image nil)
'(frame-background-mode (quote dark))
'(fringe-mode 10 nil (fringe))
'(global-hl-line-mode nil)
'(global-hl-line-sticky-flag t)
'(gnus-default-nntp-server "darkstar" t)
'(hl-line-sticky-flag t)
'(ido-mode (quote both) nil (ido))
'(indicate-buffer-boundaries (quote right))
'(indicate-empty-lines t)
'(inhibit-startup-screen t)
'(ispell-highlight-face (quote flyspell-incorrect))
'(linum-delay t)
'(linum-eager nil)
'(make-backup-files nil)
'(mouse-highlight 1)
'(nlinum-format " %5d " t)
'(nlinum-highlight-current-line nil)
'(nlinum-use-right-margin nil)
'(package-archives
(quote
(("melpa stable" . "https://stable.melpa.org/packages/")
("melpa" . "https://melpa.org/packages/")
("gnu" . "http://elpa.gnu.org/packages/"))))
'(package-enable-at-startup t)
'(package-selected-packages
(quote
(treemacs-projectile treemacs web-mode multiple-cursors yaml-mode org s fill-column-indicator ppd-sr-speedbar popup-complete ## markdown-mode+ markdown-mode use-package all-the-icons-dired vimish-fold company dired-quick-sort)))
'(scroll-bar-mode nil)
'(show-paren-mode t)
'(show-trailing-whitespace t)
'(size-indication-mode t)
'(speedbar-indentation-width 2)
'(sr-speedbar-skip-other-window-p nil)
'(tool-bar-mode nil)
'(truncate-lines t)
'(vimish-fold-indication-mode (quote left-fringe))
'(whitespace-display-mappings
(quote
((space-mark 32
[183]
[46])
(space-mark 160
[164]
[95])
(newline-mark 32
[36 32])
(tab-mark 9
[187 9]
[92 9]))))
'(whitespace-line-column 110)
'(whitespace-style (quote (face trailing spaces lines space-mark))))
;;usenet stuff (tin and slrn newsreader temporary article names)
(add-to-list 'auto-mode-alist '("\.article.*\\'" . message-mode))
(add-to-list 'auto-mode-alist '("tmpmsg.*\\'" . message-mode))
;;automatically customized faces
(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.
'(default ((t (:inherit nil :stipple nil :background "#000000" :foreground "#eeeeec" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 113 :width normal :foundry "simp" :family "Hack"))))
'(company-preview ((t (:background "deep sky blue" :foreground "black"))))
'(company-preview-common ((t (:inherit company-preview :foreground "blue"))))
'(company-preview-search ((t (:inherit company-preview :background "light salmon"))))
'(company-tooltip ((t (:background "white" :foreground "black"))))
'(cursor ((t (:background "yellow" :foreground "yellow"))))
'(dired-header ((t (:inherit font-lock-type-face :background "medium blue" :foreground "yellow" :box (:line-width 5 :color "medium blue")))))
'(font-lock-builtin-face ((t (:foreground "light slate blue" :weight bold))))
'(font-lock-comment-face ((t (:foreground "dark gray"))))
'(font-lock-constant-face ((t (:foreground "orange"))))
'(font-lock-function-name-face ((t (:foreground "cyan" :weight bold))))
'(font-lock-keyword-face ((t (:foreground "cornflower blue" :weight bold))))
'(font-lock-preprocessor-face ((t (:foreground "dark goldenrod"))))
'(font-lock-string-face ((t (:foreground "spring green"))))
'(font-lock-type-face ((t (:foreground "magenta" :weight bold))))
'(font-lock-variable-name-face ((t (:foreground "white"))))
'(gnus-cite-2 ((t (:foreground "yellow"))))
'(gnus-cite-3 ((t (:foreground "light green"))))
'(hl-line ((t (:background "blue"))))
'(line-number ((t (:background "gray15" :foreground "sandy brown"))))
'(line-number-current-line ((t (:inherit nil))))
'(linum ((t (:background "gray10" :foreground "rosy brown"))))
'(markdown-code-face ((t nil)))
'(mode-line ((t (:background "deep sky blue" :foreground "#2e3436" :box (:line-width 2 :color "deep sky blue")))))
'(mode-line-highlight ((t (:background "orange" :foreground "black" :box (:line-width 2 :color "orange")))))
'(mode-line-inactive ((t (:background "LightBlue2" :foreground "dim gray" :box (:line-width 2 :color "LightBlue2")))))
'(nlinum-current-line ((t (:background "blue" :foreground "gold" :weight bold))))
'(origami-fold-header-face ((t (:background "#edd400" :foreground "black" :box (:line-width 5 :color "yellow" :style released-button)))))
'(speedbar-separator-face ((t (:background "deep sky blue" :foreground "white" :box (:line-width 3 :color "deep sky blue")))))
'(speedbar-tag-face ((t (:foreground "yellow"))))
'(trailing-whitespace ((t (:background "LightSteelBlue4" :foreground "orange" :strike-through t))))
'(treemacs-directory-face ((t (:foreground "cyan" :weight bold :height 0.95))))
'(treemacs-file-face ((t (:inherit default :height 0.95))))
'(vimish-fold-overlay ((t (:background "red" :foreground "white" :box (:line-width 4 :color "red")))))
'(web-mode-html-attr-name-face ((t (:foreground "orange" :weight bold))))
'(web-mode-html-tag-bracket-face ((t (:foreground "red" :weight bold))))
'(web-mode-html-tag-face ((t (:foreground "light sky blue" :weight bold))))
'(whitespace-big-indent ((t (:background "red" :foreground "white"))))
'(whitespace-hspace ((t (:foreground "magenta"))))
'(whitespace-line ((t (:foreground "medium slate blue"))))
'(whitespace-space ((t (:foreground "firebrick"))))
'(whitespace-tab ((t (:foreground "darkgray"))))
'(whitespace-trailing ((t (:foreground "brightyellow" :weight bold)))))
;;run for message-mode
(defun my-message-mode-hook()
(flyspell-mode)
(auto-fill-mode)
(set-fill-column 77)
;; (nlinum-mode 1)
(whitespace-mode 1)
(setq flyspell-issue-message-flag nil)
(setq show-trailing-whitespace t)
)
;;minor improvements to message-mode
(add-hook 'message-mode-hook
#'(lambda ()
(mml-mode 0)
(setq whitespace-line-column 78)
(font-lock-add-keywords nil
'(("^[ \t]*>[ \t]*>[ \t]*>.*$"
(0 'message-multiply-quoted-text-face))
("^[ \t]*>[ \t]*>.*$"
(0 'message-double-quoted-text-face))
("^--\s\\(?:.\\|\n\\)+"
(0 'message-signature-text-face))))
(my-message-mode-hook)))
;;... and some for markdown
(add-hook 'markdown-mode-hook
#'(lambda ()
(setq whitespace-line-column 110)
(my-message-mode-hook)
(set-fill-column 90)))
;;tell ispell to check with two languages
(with-eval-after-load "ispell"
(setq ispell-program-name "hunspell")
(setq ispell-dictionary "en_US,de_DE")
;; ispell-set-spellchecker-params has to be called
;; before ispell-hunspell-add-multi-dic will work
(ispell-set-spellchecker-params)
(ispell-hunspell-add-multi-dic "en_US,de_DE"))
;; nearly all of this is the default layout
(setq ibuffer-formats
'((mark modified read-only " "
(name 50 50 :left :elide) ; change: 30s were originally 18s
" "
(size 9 -1 :right)
" "
(mode 16 16 :left :elide)
" " filename-and-process)
(mark " "
(name 16 -1)
" " filename)))
;;another thing only important for usenet posting.
(defun as-format-as-flowed-text ()
"
Format the buffer as flowed text according to RFC 2646.
This ensures that appropriate lines should be terminated with a
single space, and that \"> \" quoting prefixes are replaced with
\">\". Operates on the current region if active, otherwise on
the whole buffer.
"
(interactive)
(let ((start (if (use-region-p) (region-beginning) (point-min)))
(end (if (use-region-p) (region-end) (point-max))))
(save-excursion
(goto-char start)
;; Ensure appropriate lines end with a space
(while (re-search-forward "^\\(>+ ?\\)?\\S-.*\\S-$" end t)
(replace-match "\\& " t))
;; Replace "> " quoting prefixes with ">"
(goto-char start)
(let ((eol)
(eolm (make-marker)))
(while (setq eol (re-search-forward "^>.*" end t))
(set-marker eolm eol)
(goto-char (match-beginning 0))
(while (looking-at ">")
(if (looking-at "> ")
(replace-match "> ")
(forward-char)))
(goto-char (marker-position eolm)))))))
(bind-key "M-j M-f" 'as-format-as-flowed-text)
"
mainly for usenet posting, some old functions that allow to insert
fortunes manually for signatures and other purposes
"
(defun fortune (topic)
(interactive
(list
(read-string "Section: ")))
;;(insert-shell-command-output format("fortune -s %s" topic)))
(insert (shell-command-to-string (format "fortune -s %s" topic))))
(defun cowsay (text)
(interactive
(list
(read-string "Text:" )))
(insert (shell-command-to-string (format "echo %s | cowsay -W70" (shell-quote-argument text)))))
(defun cowfortune (text)
(interactive
(list
(read-string "Category: ")))
(insert (shell-command-to-string (format "fortune %s | cowsay -n" text))))
(setq dired-listing-switches "-lXGhA --group-directories-first")
;; syntax highlight
;; highlight operators and other special chars
(defface font-lock-operator-face
'((t (:foreground "#ff3030"))) "Basic face for operator." :group 'basic-faces)
;; C-Like
(dolist (mode-iter '(scss-mode css-mode js2-mode c-mode c++-mode emacs-lisp-mode glsl-mode java-mode javascript-mode rust-mode))
(font-lock-add-keywords mode-iter
'(("\\([~^;{}()?#§&\|!<>:=,.\\+*/%-]\\)" 0 'font-lock-operator-face keep))))
;; Scripting
(dolist (mode-iter '(python-mode lua-mode))
(font-lock-add-keywords mode-iter
'(("\\([@~^;{}()?#§&\|!<>:=,.\\+*/%-]\\)" 0 'font-lock-operator-face keep))))
;;shortcuts for vimish-fold
(require 'vimish-fold)
(vimish-fold-global-mode 1)
;; this registers a region for future folding/unfolding
(global-set-key (kbd "S-<f2>") #'vimish-fold)
;; this unregisters the region under point from folding/unfolding
(global-set-key (kbd "C-<f2>") #'vimish-fold-delete)
;; this is the actual fold/unfold command
(global-set-key (kbd "<f2>") #'vimish-fold-toggle)
;; define function to shutdown emacs server instance
;; save buffers, end the server
(defun server-shutdown ()
(interactive)
(save-some-buffers)
(kill-emacs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment