(setq m/package-dir "/home/m/.emacs.d/personal/packages/")
(setq m/theme-dir "/home/m/.emacs.d/personal/theme/") ;; directory
(setq m/theme 'personal) ;; theme name
(setq m/margins 8) ;; margins
(setq m/writing-modes '(org-mode))
(setq m/programming-modes '(js-mode
python-mode
html-mode
java-mode
c-mode
css-mode
ruby-mode
sh-mode
kotlin-mode
racket-mode
conf-mode
fundamental-mode
emacs-lisp-mode
lisp-interaction-mode))
(setq m/header-icon-face 'all-the-icons-lblue) ;; Face for icons
(setq m/indent 2)
(defun m/focused()
(list (face-remap-add-relative 'default '(:background "#fdfcff"))
(face-remap-add-relative 'header-line '(:background "#ffffff" :foreground "#677174" :overline "#ffffff" :box (:line-width 7 :color "#ffffff")))
(face-remap-add-relative 'org-hide '(:background "#fdfcff" :foreground "#fdfcff"))
(face-remap-add-relative 'org-block '(:background "#f6f8fa"))
(face-remap-add-relative 'org-agenda-filter-tags '(:box (:line-width 5 :color "#fdfcff")))
))
(setq m/spam '(
"^ "
"^\\*Buffer List\\*$"
"^\\*Backtrace\\*$"
"^\\*WoMan-Log\\*$"
"^\\*Compile-Log\\*$"
"^\\*tramp/.+\\*$"
"^\\*evil-marks\\*$"
"^\\*evil-registers\\*$"
"^\\*Shell Command Output\\*$"
"^\\*helm[- ].+\\*$"
"^\\*magit\\(-\\w+\\)?: .+$"
"^\\*irc\\..+\\*$"
"\\*helm-mode"
"\\*Echo Area"
"\\*Minibuf"
"\\ *code-conversion-work\\*"
"org-src-fontification.+"
"\\*helm-mode.+"
"\\*Org-Babel Error"))
(setq m/sidebar "/home/m/studio/sidebar.org")
(require 'openwith)
(setq openwith-associations '(
("\\.pdf\\'" "firefox" (file))
("\\.jpg\\'" "feh" (file))
("\\.png\\'" "feh" (file))
("\\.jpeg\\'" "feh" (file))))
Package repositories
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
Local packages
(add-to-list 'load-path m/package-dir)
Helm
(require 'helm)
(require 'helm-config)
(helm-mode 1)
No splash screen
(setq inhibit-splash-screen t)
No toolbar
(tool-bar-mode -1)
No menubar
(menu-bar-mode -99)
No bells
(setq visible-bell 1)
No scrollbars
(set-scroll-bar-mode nil)
(setq horizontal-scroll-bar-mode nil)
No modeline
(setq-default mode-line-format " ")
(setq helm-mode-line-string nil)
No line numbers
(setq-default line-number-mode nil)
(fringe-mode '(0 . 0))
(setq-default left-margin-width m/margins)
(setq-default right-margin-width m/margins)
Theme directory
(add-to-list 'custom-theme-load-path m/theme-dir)
Load theme
(load-theme m/theme t)
Every time you save the org
of a specified theme located in the theme directory, it will tangle, recompile and reload itself.
(defun m/hotreload-theme()
"Every time you save the org representation of `m/theme', located in m/theme-dir, it will tangle, recompile and reload itself."
(let ((m/theme-file (concat (prin1-to-string m/theme) "-theme.")))
(when (string= buffer-file-name (concat m/theme-dir m/theme-file "org"))
(org-babel-tangle-file (concat m/theme-dir m/theme-file "org")
(concat m/theme-dir m/theme-file "el"))
(byte-recompile-directory m/theme-dir)
(load-theme m/theme t)
(message (concat " :arrows-counterclockwise: " m/theme-file " theme reloaded")))))
(add-hook 'after-save-hook 'm/hotreload-theme)
The header consists of the major-mode icon and the filename or, if absent, buffername
(setq-default header-line-format
'(" "
(:eval (all-the-icons-icon-for-mode major-mode :face m/header-icon-face))
" "
(:eval (if buffer-file-name
(s-join "." (butlast (split-string (file-name-nondirectory (buffer-file-name)) "\\.")))
(buffer-name)))))
No header for helm buffers
(defun m/noheader()
(with-helm-buffer
(setq header-line-format nil)))
(add-hook 'helm-after-initialize-hook 'm/noheader)
Mouse
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1)))
(setq mouse-wheel-progressive-speed nil)
(setq mouse-wheel-follow-mouse 't)
(setq scroll-step 1)
Keyboard
(defun m/scrolldown ()
(interactive)
(scroll-up 1))
(defun m/scrollup ()
(interactive)
(scroll-down 1))
(global-set-key [(next)] 'm/scrolldown)
(global-set-key [(prior)] 'm/scrollup)
(defhydra m/winresize (:hint nil)
"← ↑ → ↓"
("<left>" (shrink-window-horizontally 10))
("<right>" (enlarge-window-horizontally 10))
("<up>" (enlarge-window 10))
("<down>" (shrink-window 10))
("q" nil)
)
(global-set-key (kbd "M-r") 'm/winresize/body)
Open
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(setq helm-ff-kill-or-find-buffer-fname-fn 'ignore)
Close
(defun m/kill-buffer ()
(interactive)
(kill-buffer (current-buffer)))
(global-set-key (kbd "C-x k") 'm/kill-buffer)
Move
(global-set-key (kbd "M-s-<left>") 'windmove-left)
(global-set-key (kbd "M-s-<right>") 'windmove-right)
(global-set-key (kbd "M-s-<up>") 'windmove-up)
(global-set-key (kbd "M-s-<down>") 'windmove-down)
Change the look of focused windows
;; Stolen from Amit Patel's highlight-focus.el
(require 'face-remap)
(defvar highlight-focus:last-buffer nil)
(defvar highlight-focus:cookie nil)
(defvar highlight-focus:app-has-focus t)
(defun highlight-focus:check ()
"Check if focus has changed, and if so, update remapping."
(let ((current-buffer (and highlight-focus:app-has-focus (current-buffer))))
(unless (eq highlight-focus:last-buffer current-buffer)
(when (and highlight-focus:last-buffer highlight-focus:cookie)
(with-current-buffer highlight-focus:last-buffer
(dolist (m/face highlight-focus:cookie)
(face-remap-remove-relative m/face))))
(setq highlight-focus:last-buffer current-buffer)
(when current-buffer
(setq highlight-focus:cookie (m/focused))
))))
(defun highlight-focus:app-focus (state)
(setq highlight-focus:app-has-focus state)
(highlight-focus:check))
(defadvice other-window (after highlight-focus activate)
(highlight-focus:check))
(defadvice select-window (after highlight-focus activate)
(highlight-focus:check))
(defadvice select-frame (after highlight-focus activate)
(highlight-focus:check))
(add-hook 'window-configuration-change-hook 'highlight-focus:check)
(add-hook 'focus-in-hook (lambda () (highlight-focus:app-focus t)))
(add-hook 'focus-out-hook (lambda () (highlight-focus:app-focus nil)))
Make helm windows pop from below
(setq helm-full-frame nil)
(setq helm-split-window-in-side-p t)
(setq helm-split-window-default-side 'below)
Make helm windows look like other focused windows and remove the header
(setq helm-display-header-line nil)
(defun m/focused-helm ()
"Visual changes for contextual buffers."
(variable-pitch-mode)
(m/focused)
(setq header-line-format nil)
(setq left-margin-width m/margins)
(setq right-margin-width m/margins))
(defun m/apply-focused-helm ()
"Apply contextual visual changes to Helm buffers."
(with-helm-buffer (m/focused-helm)))
(add-hook 'helm-after-initialize-hook 'm/apply-focused-helm)
Cycle over open buffers except those in m/spam
(require 'swbuff)
(setq swbuff-recent-buffers-first t)
(setq swbuff-separator " · ")
(setq swbuff-exclude-buffer-regexps m/spam)
(global-set-key [(C-next)] 'swbuff-switch-to-next-buffer)
(global-set-key [(C-prior)] 'swbuff-switch-to-previous-buffer)
Interactively select a buffer from open buffers, files in current directory and recently opened files
(setq helm-buffer-details-flag 'nil)
(setq helm-boring-buffer-regexp-list m/spam)
(setq helm-mini-default-sources '(
helm-source-buffers-list
helm-source-files-in-current-dir
helm-source-file-name-history
))
(global-set-key (kbd "M-SPC") 'helm-mini)
Save buffers across sessions
(desktop-save-mode 1)
Save cursor position across sessions
(require 'saveplace)
(setq-default save-place t)
UTF-8
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
Wrap long sentences
(global-visual-line-mode t)
Highlight the cursor in the focused window
(global-hl-line-mode 1)
(setq-default cursor-type 'box)
(setq-default cursor-in-non-selected-windows nil)
Space between lines
(setq-default line-spacing 3)
Emoji
(add-hook 'after-init-hook #'global-emojify-mode)
Between lines
(setq-default line-move-visual nil)
(global-set-key (kbd "<up>") 'previous-line)
(global-set-key (kbd "<down>") 'next-line)
To the begining or end of line
(global-set-key (kbd "<C-right>") 'end-of-line)
(global-set-key (kbd "<C-left>") 'beginning-of-line)
Select all
(global-set-key (kbd "C-a") 'mark-whole-buffer)
(define-key org-mode-map [(control a)] 'mark-whole-buffer)
Write over the range
(delete-selection-mode 1)
No automatic backups
(setq make-backup-files nil)
(setq auto-save-default nil)
(setq create-lockfiles nil)
Revert buffer when changed on disk
(global-auto-revert-mode 1)
(setq default-tab-width m/indent)
(setq css-indent-offset m/indent)
(setq js-indent-level m/indent)
(setq js2-basic-indent m/indent)
(setq js2-basic-offset m/indent)
(setq python-indent-offset m/indent)
(setq indent-tabs-mode nil)
(global-set-key (kbd "C-z") 'undo)
Hide markers
(setq org-hide-emphasis-markers t)
Follow links
(setq org-return-follows-link t)
(setq browse-url-browser-function 'browse-url-xdg-open)
Select with shift
(setq org-support-shift-select 'always)
Move lines up or down
(defun m/move-line (arg)
"Drag the line at point ARG lines forward."
(interactive "p")
(dotimes (_ (abs arg))
(let ((c (current-column)))
(if (< 0 arg)
(progn
(beginning-of-line 2)
(transpose-lines 1)
(beginning-of-line 0))
(transpose-lines 1)
(beginning-of-line -1)))))
(defun m/move-line-up()
(interactive)
(m/move-line -1))
(defun m/move-line-down()
(interactive)
(m/move-line 1))
(global-set-key (kbd "<M-S-up>") 'm/move-line-up)
(global-set-key (kbd "<M-S-down>") 'm/move-line-down)
(define-key global-map (kbd "C-s") 'swiper)
Monospace font
(defun m/apply-monofont ()
(interactive)
(setq buffer-face-mode-face '(:family "Hack"))
(buffer-face-mode))
Line numbers format
(setq linum-format " %d ")
Apply monospace fonts, line numbers and rainbow delimiters
(defun m/programming()
(m/apply-monofont)
(linum-mode 1)
(rainbow-delimiters-mode))
(dolist (m/mode m/programming-modes)
(add-hook (derived-mode-hook-name m/mode) 'm/programming))
Global smartparens
(require 'smartparens-config)
(smartparens-global-mode)
Setup auto-complete
(ac-config-default)
(setq ac-auto-start nil)
(define-key ac-mode-map (kbd "M-TAB") 'auto-complete)
Search all files within a directory
(require 'ag)
(global-set-key (kbd "M-.") 'helm-do-ag)
A clean js2-mode look
(setq-default js2-auto-indent-p t)
(setq-default js2-cleanup-whitespace t)
(setq-default js2-indent-on-enter-key t)
(setq js2-mode-show-parse-errors nil)
(setq js2-mode-show-strict-warnings nil)
(defun m/js2comments ()
(setq comment-start "//"
comment-end ""
comment-style 'indent))
(add-hook 'js2-mode-hook #'m/js2comments)
Use eslint in node_modules
(defun m/js2eslint ()
(let* ((root (locate-dominating-file
(or (buffer-file-name) default-directory)
"node_modules"))
(eslint (and root
(expand-file-name "node_modules/eslint/bin/eslint.js"
root))))
(when (and eslint (file-executable-p eslint))
(setq-local flycheck-javascript-eslint-executable eslint))))
(add-hook 'flycheck-mode-hook #'m/js2eslint)
Use in all .js files
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
Make sure you’re using python 3
(setq-default elpy-rpc-python-command "python3")
(setq-default python-shell-interpreter "python3")
Indentation
(setq org-startup-indented t)
(setq-default org-adapt-indentation t)
(setq-default org-indent-indentation-per-level 2)
(defun m/org-heading-lookfix()
(interactive)
(setq org-adapt-indentation nil)
(require 'org-bullets)
(setq-default org-bullets-bullet-list '( "•"))
(setq org-bullets-compose-leading-stars 'hide)
(org-bullets-mode 1)
(setq org-bullets-face-name 'org-agenda-filter-tags))
(add-hook 'org-mode-hook 'm/org-heading-lookfix)
Bullets
(setq-default org-hide-leading-stars t)
Ellipsis and separation between collapsed headings
(setq org-ellipsis " ")
(setq org-cycle-separator-lines 0)
TODO keywords
(setq-default org-todo-keywords `((sequence "⭕" "✅")))
Tags
(setq org-tags-column 0)
Cycle
(define-key org-mode-map [(control shift down)] 'outline-next-visible-heading)
(define-key org-mode-map [(control shift up)] 'outline-previous-visible-heading)
Copy a link to a heading
(defun m/org-heading-link (marker)
(with-current-buffer (marker-buffer marker)
(let ((heading-name (save-excursion (goto-char (marker-position marker))
(nth 4 (org-heading-components))))
(file-name (buffer-file-name)))
(with-helm-current-buffer
(org-insert-link file-name (concat "file:" file-name "::*" heading-name) (concat "🔗 " heading-name)))
)))
Go to a heading
(setq helm-org-headings-actions '(("Go to" . helm-org-goto-marker)
("Insert link" . m/org-heading-link)))
(setq helm-org-format-outline-path t)
(define-key org-mode-map (kbd "C-/") 'helm-org-in-buffer-headings)
I tend to have files where I don’t want to worry about heading titles or document structure. In this case, I make M-RET
create only numbered headings from 1
onwards. I bind this to a minor mode that I can apply at the top of any of these files.
(defun m/org-insert-numbered-heading ()
"Create a heading titled as the next integer"
(interactive)
(let ((m/numbered-headings (org-map-entries (lambda () (nth 4 (org-heading-components))) nil 'file)))
(setq m/new-heading (number-to-string (+ 1 (string-to-number (car (last m/numbered-headings))))))
(org-insert-heading)
(insert (concat m/new-heading "\n\n"))
))
(define-minor-mode m/org-spontaneous-writing-mode
"Minor mode to for simple exploratory writing"
:lighter " Spontaneous writing"
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "M-RET") 'm/org-insert-numbered-heading)
map))
(require 'org-tempo)
(setq org-structure-template-alist '(("s" . "src")
("q" . "quote")))
Prose and code feature different fonts
(add-hook 'org-mode-hook 'variable-pitch-mode)
(setq-default org-fontify-quote-and-verse-blocks t)
(setq org-src-fontify-natively t)
Block indentation
(setq-default org-edit-src-content-indentation 1)
Display icons for blocks
(setq-default prettify-symbols-alist '(
("#+TITLE:". "")
(":PROPERTIES:" . ":")
("#+BEGIN_SRC" . "λ")
("#+END_SRC" . "⋱")
("#+begin_src" . "λ")
("#+end_src" . "⋱")
("#+RESULTS:" . "»")
(":END:" . "⋱")
(":RESULTS:" . "⋰")
("#+name:" . "")
("#+BEGIN_EXAMPLE" . "~")
("#+begin_example" . "~")
("#+END_EXAMPLE" . "~")
("#+end_example" . "~")
("#+BEGIN_VERBATIM" . "")
("#+END_VERBATIM" . "")
("#+BEGIN_VERSE" . "")
("#+END_VERSE" . "")
("#+begin_quote" . "~")
("#+end_quote" . "~")
("#+TBLFM:" . "∫")))
(add-hook 'org-mode-hook 'prettify-symbols-mode)
Open in the same window
(setq org-src-window-setup 'current-window)
Run without confirmation
(setq org-confirm-babel-evaluate nil)
Languages
(org-babel-do-load-languages
'org-babel-load-languages '((emacs-lisp . t)
(shell . t)
(python . t)
(js . t)))
Bash
(setq org-babel-default-header-args:sh '((:results . "verbatim pp replace")))
(setq explicit-shell-file-name "/bin/bash")
(setq-default shell-file-name "bash")
(setq explicit-bash-args '("-c" "export EMACS=; stty echo; bash"))
Python
(setq org-babel-python-command "python3")
(setq org-babel-default-header-args:python '((:results . "verbatim pp replace output")))
Inhert properties from above the tree
(setq org-use-property-inheritance t)
Server
(server-start)
(require 'org-protocol)
Select interactively where to place captures: just C-.
where you want them to go
(defvar m/capture-file '())
(defvar m/capture-persist "~/.emacs.d/.capture")
(defun m/goto-capture ()
"Go to m/capture-file and place the cursor at the bottom"
(interactive)
(find-file (nth 0 m/capture-file))
(org-goto-marker-or-bmk (org-find-exact-headline-in-buffer (nth 1 m/capture-file)))
(outline-next-heading)
(newline)
(left-char)
)
(defun m/capture-here ()
"Select a file and heading to write captures to."
(interactive)
(let ((m/capture-here-file (buffer-file-name (org-base-buffer (nth 0 (org-buffer-list "files")))))
(m/capture-here-heading (substring-no-properties (org-get-heading))))
(setq m/capture-file (list m/capture-here-file m/capture-here-heading))
(message (concat m/capture-here-file " --> " m/capture-here-heading))
))
(global-set-key (kbd "C-.") 'm/capture-here)
Format captures as links or quotes
(setq org-capture-templates
'(
("l"
"Capture a link"
plain
(function m/goto-capture)
"\n\n[[%:link][%:description]]\n\n"
:immediate-finish t :jump-to-captured nil :empty-lines 1)
("q"
"Capture a quote"
plain
(function m/goto-capture)
"/%:initial/"
:immediate-finish t :jump-to-captured nil :empty-lines 1)
))
A sidebar I can bring at any moment that displays useful information.
Visual changes to apply so that it looks different
(defun m/index-faces ()
(setq header-line-format nil)
(face-remap-add-relative 'default '(:background "#f8f7fa" :foreground "#aba1a2"))
(face-remap-add-relative 'org-level-1 '(:foreground "#756a6b"))
(face-remap-add-relative 'org-hide '(:background "#f8f7fa"))
(face-remap-add-relative 'org-agenda-filter-tags '(:background "#f8f7fa" :foreground "#ff6678") :box '(:line-width 5 :color "#f8f7fa"))
(face-remap-add-relative 'org-block-begin-line '(:background "#f8f7fa"))
(face-remap-add-relative 'org-block-end-line '(:background "#f8f7fa"))
(face-remap-add-relative 'org-block '(:background "#f3f2f5"))
)
Easily toggle from anywhere
(defun m/showindex ()
"Show the index of current projects"
(let ((buffer (get-file-buffer m/sidebar)))
(progn
(display-buffer-in-side-window buffer '((side . left) (window-width . 0.25)))
(set-window-dedicated-p (get-buffer-window buffer) t)
(select-window (get-buffer-window buffer))
(m/index-faces)
)))
(defun m/hideindex ()
"Hide the index of current projects"
(let ((buffer (get-file-buffer m/sidebar)))
(progn
(delete-window (get-buffer-window buffer))
)))
(defun m/toggleindex ()
"Toggle the index of current projects"
(interactive)
(let* ((buffer (get-file-buffer m/sidebar))
(window (get-buffer-window buffer)))
(if window
(m/hideindex)
(m/showindex)
)))
(global-set-key (kbd "C-M-SPC") 'm/toggleindex)
(define-key global-map (kbd "M-x") 'helm-M-x)
Open in current directory
(global-set-key (kbd "C-x C-d") 'dired-jump)
Display a simple list
(require 'dired-details)
(dired-details-install)
(setq dired-details-hidden-string "")
Show icons
(add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
Browse up, down and within directory levels
(defun m/dired-go-up ()
(interactive)
(find-alternate-file ".."))
(eval-after-load "dired" '(progn
(define-key dired-mode-map (kbd "/") 'dired-narrow)
(define-key dired-mode-map (kbd "M-<left>") 'm/dired-go-up)
(define-key dired-mode-map (kbd "M-<right>") 'dired-find-alternate-file)))
(define-key helm-find-files-map (kbd "M-<left>") 'helm-find-files-up-one-level)
(define-key helm-find-files-map (kbd "M-<right>") 'helm-ff-RET)
Sort directories first
(setq dired-listing-switches "-al --group-directories-first")
Delete directories without confirmation
(setq dired-recursive-deletes 'always)
Apply default application selections and work around a bug that affects inline image display in org-mode.
(openwith-mode t)
(defadvice org-display-inline-images
(around handle-openwith
(&optional include-linked refresh beg end) activate compile)
(if openwith-mode
(progn
(openwith-mode -1)
ad-do-it
(openwith-mode 1))
ad-do-it))