Human Readable Emacs Configuration using Org mode
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1513 lines
57 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. ;;; -*- lexical-binding: t -*-
  2. ;;; DO NOT EDIT THIS FILE DIRECTLY
  3. ;;; EDIT ~init.org~ instead
  4. ;; (setq byte-compile-warnings nil)
  5. (defun tangle-init ()
  6. "If the current buffer is 'init.org' the code-blocks are tangled, and the tangled file is compiled."
  7. (when (equal (buffer-file-name)
  8. (expand-file-name (concat user-emacs-directory "init.org")))
  9. ;; Avoid running hooks when tangling.
  10. (let ((prog-mode-hook nil))
  11. (org-babel-tangle)
  12. (byte-compile-file (concat user-emacs-directory "init.el")))))
  13. (add-hook 'after-save-hook 'tangle-init)
  14. (require 'package)
  15. (package-initialize)
  16. (defvar my-packages
  17. '(all-the-icons
  18. anzu
  19. base16-theme
  20. bbdb
  21. better-defaults
  22. company
  23. company-go
  24. counsel
  25. counsel-projectile
  26. dash-at-point
  27. dashboard
  28. diminish
  29. dockerfile-mode
  30. doom-modeline
  31. doom-themes
  32. ein
  33. eldoc-eval
  34. elfeed
  35. elfeed-org
  36. elpy
  37. emmet-mode
  38. expand-region
  39. fic-mode
  40. flycheck
  41. gitignore-mode
  42. go-mode
  43. go-playground
  44. gorepl-mode
  45. iedit
  46. ivy
  47. ivy-hydra
  48. jabber
  49. json-mode
  50. magit
  51. material-theme
  52. multiple-cursors
  53. projectile
  54. rainbow-delimiters
  55. rust-mode
  56. shrink-path
  57. tide
  58. typescript-mode
  59. ;; use-package
  60. web-mode
  61. which-key))
  62. (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
  63. (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/"))
  64. (when (not package-archive-contents)
  65. (package-refresh-contents))
  66. (package-initialize)
  67. (dolist (p my-packages)
  68. (when (not (package-installed-p p))
  69. (package-install p)))
  70. (require 'better-defaults)
  71. ;; Instead of the annoying giant warning icon, just flash the modeline.
  72. ;; (this happens when you do something like C-g)
  73. (setq ring-bell-function
  74. (lambda ()
  75. (let ((orig-fg (face-foreground 'mode-line)))
  76. (set-face-foreground 'mode-line "#F2804F")
  77. (run-with-idle-timer 0.1 nil
  78. (lambda (fg) (set-face-foreground 'mode-line fg))
  79. orig-fg))))
  80. (defun set-frame-size-according-to-resolution ()
  81. "Set the Emacs window size on startup."
  82. (interactive)
  83. (if window-system
  84. (progn
  85. ;; WIDTH
  86. (if (> (x-display-pixel-width) 1280)
  87. ;; Large Screen (only show 120 cols)
  88. (add-to-list 'default-frame-alist (cons 'width 240))
  89. ;; Small Screen (fill window)
  90. (add-to-list 'default-frame-alist (cons 'width (/ (x-display-pixel-width) (frame-char-width)))))
  91. ;; HEIGHT
  92. (if (> (x-display-pixel-height) 1080)
  93. ;; Large Screen (only fill half screen)
  94. (add-to-list 'default-frame-alist (cons 'height (/ (/ (x-display-pixel-height) 2)
  95. (frame-char-height))))
  96. ;; Small Screen (fill window)
  97. (add-to-list 'default-frame-alist (cons 'height (/ (x-display-pixel-height) (frame-char-height)))))
  98. )))
  99. (set-frame-size-according-to-resolution)
  100. (defun window-px-width ()
  101. "Get the width of the Emacs window in pixels."
  102. (interactive)
  103. (* (* (window-total-width) 2.874) (frame-char-width)))
  104. (defun window-px-left-pos ()
  105. "Calculate the left position of the Emacs window."
  106. (interactive)
  107. (/ (- (x-display-pixel-width) (window-px-width)) 2))
  108. (add-to-list 'default-frame-alist (cons 'top 0))
  109. (add-to-list 'default-frame-alist (cons 'left 1000))
  110. (put 'narrow-to-region 'disabled nil)
  111. (put 'upcase-region 'disabled nil)
  112. (put 'downcase-region 'disabled nil)
  113. (require 'dashboard)
  114. (dashboard-setup-startup-hook)
  115. ;; Set the title
  116. (setq dashboard-banner-logo-title "Let's begin...")
  117. ;; Set the banner
  118. (setq dashboard-startup-banner "~/.emacs.d/public/emacs-logo-512.png")
  119. ;; Value can be
  120. ;; 'official which displays the official emacs logo
  121. ;; 'logo which displays an alternative emacs logo
  122. ;; 1, 2 or 3 which displays one of the text banners
  123. ;; "path/to/your/image.png" which displays whatever image you would prefer
  124. ;; Content is not centered by default. To center, set
  125. (setq dashboard-center-content t)
  126. ;; To disable shortcut "jump" indicators for each section, set
  127. (setq dashboard-show-shortcuts t)
  128. (setq show-week-agenda-p t)
  129. (setq dashboard-items '((recents . 5)
  130. (bookmarks . 5)
  131. (projects . 5)
  132. (agenda . 5)
  133. (registers . 5)))
  134. (defvar backup-dir (expand-file-name "~/.emacs.d/backup/"))
  135. (defvar autosave-dir (expand-file-name "~/.emacs.d/autosave/"))
  136. (setq initial-scratch-message nil
  137. backup-directory-alist (list (cons ".*" backup-dir))
  138. auto-save-list-file-prefix autosave-dir
  139. auto-save-file-name-transforms `((".*" ,autosave-dir t)))
  140. (menu-bar-mode 0)
  141. (scroll-bar-mode 0)
  142. (tool-bar-mode 0)
  143. (setq auth-sources '("~/.authinfo.gpg"))
  144. (set-default 'truncate-lines t)
  145. ;; (load-theme 'doom-city-lights t)
  146. ;; (load-theme 'doom-dracula t)
  147. ;; (load-theme 'doom-nord t)
  148. (load-theme 'doom-one t)
  149. ;; (load-theme 'doom-spacegrey t)
  150. ;; (load-theme 'base16-ocean t)
  151. (load-theme 'base16-onedark t)
  152. (global-linum-mode t)
  153. (global-auto-revert-mode t)
  154. (defalias 'yes-or-no-p 'y-or-n-p)
  155. (defvar diary-file (expand-file-name "~/.emacs.d/diary/main"))
  156. (add-hook 'diary-list-entries-hook 'diary-sort-entries t)
  157. (add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
  158. (add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)
  159. (add-hook 'calendar-today-visible-hook 'calendar-mark-today)
  160. (setq calendar-latitude 44
  161. calendar-longitude -97
  162. calendar-location-name "Hayti, SD")
  163. (require 'font-lock)
  164. (defvar openhab-mode-hook nil)
  165. (defvar openhab-mode-map
  166. (let ((map (make-keymap)))
  167. (define-key map "\C-j" 'newline-and-indent)
  168. map)
  169. "Keymap for OPENHAB major mode.")
  170. (add-to-list 'auto-mode-alist '("\\.sitemap\\'" . openhab-mode))
  171. (add-to-list 'auto-mode-alist '("\\.items\\'" . openhab-mode))
  172. (add-to-list 'auto-mode-alist '("\\.rules\\'" . openhab-mode))
  173. (add-to-list 'auto-mode-alist '("\\.things\\'" . openhab-mode))
  174. (defconst openhab-font-lock-keywords
  175. `(
  176. ("\<.*\>" . font-lock-constant-face)
  177. (,(regexp-opt
  178. '(
  179. ;; KEYWORDS
  180. "Selection" "Slider" "List" "Setpoint" "Video" "Chart" "Webview" "Colorpicker"
  181. "Timer" "Number" "String"
  182. "Switch" "Rollershutter" "Number" "String" "Dimmer" "Contact" "DateTime" "Color"
  183. "Text" "Group" "Image" "Frame"
  184. "Thing" "Bridge"
  185. "Time" "System"
  186. "sitemap"
  187. "rule" "when" "then" "end"
  188. "if" "val"
  189. "import" "var" "say" "postUpdate" "switch" "println" "case" "or" "sendCommand"
  190. )
  191. 'words)
  192. (1 font-lock-keyword-face))
  193. (,(regexp-opt
  194. '(
  195. "ON" "OFF" "on" "off"
  196. "AND" "OR" "NAND" "NOR" "AVG" "SUM" "MAX" "MIN"
  197. "true" "false"
  198. )
  199. 'words)
  200. (1 font-lock-constant-face))
  201. (,(regexp-opt
  202. '(
  203. "name" "label" "item" "period" "refresh" "icon" "mappings" "minValue" "maxValue" "step" "switchsupport" "url" "height" "refresh" "visibility" "valuecolor"
  204. )
  205. 'words)
  206. (1 font-lock-type-face))
  207. ("\(.*\)" . font-lock-variable-name-face)
  208. ("[^a-zA-Z0-9_:]\\([0-9]*\\)[^a-zA-Z0-9_:]" . (1 font-lock-variable-name-face))
  209. ("\s@\s" . font-lock-variable-name-face)
  210. ("\s\\([a-zA-Z0-9_:]*\\)\\(\s\\|$\\)" . (1 font-lock-type-face))
  211. ("=\\([a-zA-Z_]*\\)" . (1 font-lock-string-face))
  212. ("\\([a-zA-Z]*\\)=" . (1 font-lock-type-face))
  213. )
  214. "The regexps to highlight in openHAB mode.")
  215. (defvar openhab-mode-syntax-table
  216. (let ((st (make-syntax-table)))
  217. (modify-syntax-entry ?/ ". 12b" st) ;; C-style comments // ...
  218. (modify-syntax-entry ?\n "> b" st) ;; \n ends comment
  219. ;; Block comments /*...*/
  220. (modify-syntax-entry ?\/ ". 14" st)
  221. (modify-syntax-entry ?* ". 23" st)
  222. st)
  223. "Syntax table for openhab-mode.")
  224. (defun openhab-mode ()
  225. "Major mode for editing OPENHAB config files."
  226. (interactive)
  227. (kill-all-local-variables)
  228. (set-syntax-table openhab-mode-syntax-table)
  229. (use-local-map openhab-mode-map)
  230. (set (make-local-variable 'font-lock-defaults) '(openhab-font-lock-keywords nil t))
  231. (electric-pair-mode -1)
  232. (flycheck-mode -1)
  233. (setq major-mode 'openhab-mode)
  234. (setq mode-name "OpenHAB")
  235. (run-hooks 'openhab-mode-hook))
  236. (provide 'openhab-mode)
  237. ;;; hyperspace.el --- Get there from here -*- lexical-binding: t; -*-
  238. ;; Copyright (C) 2017-2019 Ian Eure
  239. ;; Author: Ian Eure <ian@retrospec.tv>
  240. ;; URL: https://github.com/ieure/hyperspace-el
  241. ;; Version: 0.8.4
  242. ;; Package-Requires: ((emacs "25") (s "1.12.0"))
  243. ;; Keywords: tools, convenience
  244. ;; This program is free software; you can redistribute it and/or modify
  245. ;; it under the terms of the GNU General Public License as published by
  246. ;; the Free Software Foundation, either version 3 of the License, or
  247. ;; (at your option) any later version.
  248. ;; This program is distributed in the hope that it will be useful,
  249. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  250. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  251. ;; GNU General Public License for more details.
  252. ;; You should have received a copy of the GNU General Public License
  253. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  254. ;;; Commentary:
  255. ;; Hyperspace is a way to get nearly anywhere from wherever you are,
  256. ;; whether that's within Emacs or on the web. It's somewhere in
  257. ;; between Quicksilver and keyword URLs, giving you a single,
  258. ;; consistent interface to get directly where you want to go. It’s
  259. ;; for things that you use often, but not often enough to justify a
  260. ;; dedicated binding.
  261. ;;
  262. ;; When you enter Hyperspace, it prompts you where to go:
  263. ;;
  264. ;; HS:
  265. ;;
  266. ;; This prompt expects a keyword and a query. The keyword picks where
  267. ;; you want to go, and the remainder of the input is an optional
  268. ;; argument which can be used to further search or direct you within
  269. ;; that space.
  270. ;;
  271. ;; Some concrete examples:
  272. ;;
  273. ;; | *If you enter* | *then Hyperspace* |
  274. ;; |------------------+----------------------------------------------------------|
  275. ;; | "el" | opens info node "(elisp)Top" |
  276. ;; | "el eval-region" | searches for "eval-region" in the elisp Info index |
  277. ;; | "bb" | shows all BBDB entries |
  278. ;; | "bb kenneth" | shows all BBDB entries with a name matching "kenneth" |
  279. ;; | "ddg foo" | searches DuckDuckGo for "foo" using browse-url |
  280. ;; | "wp foo" | searches Wikipedia for "foo" using browse-url |
  281. ;;
  282. ;;; Code:
  283. (require 'subr-x)
  284. (require 's)
  285. ;; Action helpers
  286. (defun hyperspace-action->browse-url-pattern (pattern query)
  287. "Browse a URL former from PATTERN and QUERY."
  288. (browse-url (format pattern query)))
  289. (defun hyperspace-action->info (node &optional query)
  290. "Open an Info buffer for NODE.
  291. If QUERY is present, look it up in the index."
  292. (info node)
  293. (when query
  294. (Info-index query)))
  295. ;; Package definitions
  296. (defvar hyperspace-history nil
  297. "History of Hyperspace actions.")
  298. (defgroup hyperspace nil
  299. "Getting there from here"
  300. :prefix "hyperspace-"
  301. :group 'applications)
  302. (defcustom hyperspace-actions
  303. '(("ddg" . "https://duckduckgo.com/?q=%s")
  304. ("dis" . "https://duckduckgo.com/?q=%s&iax=images&ia=images")
  305. ("wp" . "https://en.wikipedia.org/wiki/%s")
  306. ("g" . "https://www.google.com/search?q=%s")
  307. ("gi" . "https://www.google.com/search?tbm=isch&q=%s")
  308. ("gm" . "https://www.google.com/maps/search/%s")
  309. ("yt" . "https://www.youtube.com/results?search_query=%s")
  310. ("clp" . "https://portland.craigslist.org/search/sss?query=%s")
  311. ("eb" . "https://www.ebay.com/sch/i.html?_nkw=%s")
  312. ("nf" . "https://www.netflix.com/search?q=%s")
  313. ("sh" . (lambda (query) (interactive) (shell-command query)))
  314. ("imdb" . "https://www.imdb.com/find?q=peter+jackson&s=all")
  315. ("bb" . bbdb-search-name)
  316. ("el" . (apply-partially #'hyperspace-action->info "(elisp)Top"))
  317. ("av" . apropos-variable)
  318. ("ac" . apropos-command)
  319. ("af" . (lambda (query) (apropos-command query t))))
  320. "Where Hyperspace should send you.
  321. Hyperspace actions are a cons of (KEYWORD . DISPATCHER). When
  322. Hyperspace is invoked, the keyword is extracted from the user
  323. input and looked up in this alist. The remainder of the
  324. string is passed to the dispatcher as its QUERY argument.
  325. DISPATCHER can be a function which performs the action.
  326. DISPATCHER can also be an expression which returns a function
  327. to perform the action.
  328. Finally, DISPATCHER can be a string with a URL pattern containing
  329. '%s'. The '%s' will be replaced with the query, and the URL browsed."
  330. :group 'hyperspace
  331. :type '(alist :key-type (string :tag "Keyword")
  332. :value-type (choice
  333. (function :tag "Function")
  334. (string :tag "URL Pattern")
  335. (sexp :tag "Expression"))))
  336. (defcustom hyperspace-default-action
  337. (caar hyperspace-actions)
  338. "A place to go if you don't specify one."
  339. :group 'hyperspace
  340. :type `(radio
  341. ,@(mapcar (lambda (action) (list 'const (car action))) hyperspace-actions)))
  342. (defcustom hyperspace-max-region-size 256
  343. "Maximum size of a region to consider for a Hyperspace query.
  344. If the region is active when Hyperspace is invoked, it's used
  345. as the default query, unless it's more than this number of
  346. characters."
  347. :group 'hyperspace
  348. :type 'integer)
  349. (defun hyperspace--cleanup (text)
  350. "Clean TEXT so it can be used for a Hyperspace query."
  351. (save-match-data
  352. (string-trim
  353. (replace-regexp-in-string (rx (1+ (or blank "\n"))) " " text))))
  354. (defun hyperspace--initial-text ()
  355. "Return the initial text.
  356. This is whatever's in the active region, but cleaned up."
  357. (when (use-region-p)
  358. (let* ((start (region-beginning))
  359. (end (region-end))
  360. (size (- end start)))
  361. (when (<= size hyperspace-max-region-size)
  362. (hyperspace--cleanup
  363. (buffer-substring-no-properties start end))))))
  364. (defun hyperspace--initial (initial-text)
  365. "Turn INITIAL-TEXT into INITIAL-CONTENTS for reading."
  366. (when initial-text (cons (concat " " initial-text) 1)))
  367. (defun hyperspace--process-input (text)
  368. "Process TEXT into an actionable keyword and query."
  369. (let ((kw-text (s-split-up-to "\\s-+" text 1)))
  370. (if (assoc (car kw-text) hyperspace-actions)
  371. kw-text
  372. (list hyperspace-default-action text))))
  373. (defun hyperspace--query ()
  374. "Ask the user for the Hyperspace action and query.
  375. Returns (KEYWORD . QUERY).
  376. If the region isn't active, the user is prompted for the
  377. action and query.
  378. If the region is active, its text is used as the initial value
  379. for the query, and the user enters the action.
  380. If a prefix argument is specified and the region is active,
  381. `HYPERSPACE-DEFAULT-ACTION' is chosen without prompting."
  382. (let ((initial (hyperspace--initial-text)))
  383. (if (and initial current-prefix-arg)
  384. (list hyperspace-default-action initial)
  385. (hyperspace--process-input
  386. (read-from-minibuffer "HS: " (hyperspace--initial initial) nil nil
  387. 'hyperspace-history)))))
  388. (defun hyperspace--evalable-p (form)
  389. "Can FORM be evaluated?"
  390. (and (listp form)
  391. (or (functionp (car form))
  392. (subrp (car form)))))
  393. (defun hyperspace--dispatch (action &optional query)
  394. "Execute ACTION, with optional QUERY argument."
  395. (pcase action
  396. ((pred functionp) (funcall action query))
  397. ((pred hyperspace--evalable-p) (funcall (eval action) query))
  398. ((pred stringp) (hyperspace-action->browse-url-pattern action query))
  399. (_ (error "Unknown action"))))
  400. ;;;###autoload
  401. (defun hyperspace (keyword &optional query)
  402. "Execute action for keyword KEYWORD, with optional QUERY."
  403. (interactive (hyperspace--query))
  404. (let ((action (cdr (assoc keyword hyperspace-actions))))
  405. (hyperspace--dispatch (or action hyperspace-default-action) query)))
  406. ;;;###autoload
  407. (defun hyperspace-enter (&optional query)
  408. "Enter Hyperspace, sending QUERY to the default action.
  409. If the region is active, use that as the query for
  410. hyperspace-default-action. Otherwise, prompt the user."
  411. (interactive (list (hyperspace--initial-text)))
  412. (hyperspace
  413. hyperspace-default-action
  414. (or query
  415. (read-from-minibuffer
  416. (format "HS: %s " hyperspace-default-action) nil nil
  417. 'hyperspace-history))))
  418. ;; Minor mode
  419. (defvar hyperspace-minor-mode-map
  420. (let ((kmap (make-sparse-keymap)))
  421. (define-key kmap (kbd "H-SPC") #'hyperspace)
  422. (define-key kmap (kbd "<H-return>") #'hyperspace-enter)
  423. kmap))
  424. ;;;###autoload
  425. (define-minor-mode hyperspace-minor-mode
  426. "Global (universal) minor mode to jump from here to there."
  427. nil nil hyperspace-minor-mode-map
  428. :group 'hyperspace
  429. :global t)
  430. (provide 'hyperspace)
  431. ;;; hyperspace.el ends here
  432. (require 'which-key)
  433. (which-key-setup-minibuffer)
  434. (which-key-mode)
  435. (require 'fic-mode)
  436. (add-hook 'js-mode-hook 'fic-mode)
  437. (require 'company)
  438. (add-hook 'after-init-hook 'global-company-mode)
  439. (setq company-dabbrev-downcase nil)
  440. (setq company-idle-delay 0.1)
  441. (require 'diminish)
  442. (diminish 'auto-revert-mode)
  443. (eval-after-load "company" '(diminish 'company-mode))
  444. (eval-after-load "counsel" '(diminish 'counsel-mode))
  445. (eval-after-load "elpy" '(diminish 'elpy-mode))
  446. (eval-after-load "go-mode" '(diminish 'go-mode))
  447. (eval-after-load "go-playground" '(diminish 'go-playground-mode))
  448. (eval-after-load "gorepl-mode" '(diminish 'gorepl-mode))
  449. (eval-after-load "flycheck" '(diminish 'flycheck-mode))
  450. (eval-after-load "ivy" '(diminish 'ivy-mode))
  451. (eval-after-load "projectile" '(diminish 'projectile-mode))
  452. (eval-after-load "which-key" '(diminish 'which-key-mode))
  453. (defun dired-mode-setup ()
  454. "Will run as hook for `dired-mode'."
  455. (dired-hide-details-mode nil))
  456. (add-hook 'dired-mode-hook 'dired-mode-setup)
  457. (require 'ivy-hydra)
  458. (require 'ivy)
  459. (require 'swiper)
  460. (ivy-mode 1)
  461. (counsel-mode)
  462. (setq ivy-use-virtual-buffers t
  463. enable-recursive-minibuffers t
  464. ivy-height 25
  465. ivy-initial-inputs-alist nil
  466. ivy-extra-directories nil)
  467. (global-set-key (kbd "C-s") 'swiper)
  468. (global-set-key (kbd "C-c C-r") 'ivy-resume)
  469. (global-set-key (kbd "M-x") 'counsel-M-x)
  470. (global-set-key (kbd "C-x C-f") 'counsel-find-file)
  471. (global-set-key (kbd "C-c g") 'counsel-git)
  472. (global-set-key (kbd "C-c j") 'counsel-git-grep)
  473. (global-set-key (kbd "C-c k") 'counsel-ag)
  474. (define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)
  475. (defun ivy-open-current-typed-path ()
  476. (interactive)
  477. (when ivy--directory
  478. (let* ((dir ivy--directory)
  479. (text-typed ivy-text)
  480. (path (concat dir text-typed)))
  481. (delete-minibuffer-contents)
  482. (ivy--done path))))
  483. (define-key ivy-minibuffer-map (kbd "<return>") 'ivy-alt-done)
  484. (define-key ivy-minibuffer-map (kbd "C-f") 'ivy-open-current-typed-path)
  485. (require 'magit)
  486. (global-set-key (kbd "C-x g") 'magit-status)
  487. (global-set-key (kbd "C-c g") 'magit-status)
  488. (setq magit-completing-read-function 'ivy-completing-read)
  489. (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu/mu4e")
  490. (require 'mu4e)
  491. ;; default
  492. (setq mu4e-maildir "~/Mail"
  493. mu4e-mu-binary "/usr/local/bin/mu"
  494. mu4e-change-filenames-when-moving t ;; Rename files when moving (required by mbsync)
  495. mu4e-compose-in-new-frame t ;; New compose gets new frame
  496. mu4e-context-policy 'pick-first
  497. mu4e-get-mail-command "mbsync -a" ;; MBSYNC is the mail cmd
  498. mu4e-html2text-command "/usr/local/bin/w3m -T text/html" ;; HTML to text command
  499. mu4e-headers-include-related nil ;; Stop threading in INBOX
  500. mu4e-sent-messages-behavior 'delete ;; Delete sent messages
  501. mu4e-update-interval 300 ;; 5 mins
  502. mu4e-use-fancy-chars t ;; use 'fancy' chars
  503. mu4e-user-mail-address-list '("lolson@eaglecrk.com"
  504. "lolson@vlocity.com"
  505. "olson.levi@gmail.com")
  506. mu4e-view-show-images t ;; attempt to show images
  507. mu4e-view-image-max-width 400 ;; max image size
  508. message-citation-line-format "On %a %d %b %Y at %R, %f wrote:\n" ;; customize the reply-quote-string
  509. message-citation-line-function 'message-insert-formatted-citation-line ;; choose to use the formatted string
  510. message-kill-buffer-on-exit t ;; don't keep messages around
  511. send-mail-function 'smtpmail-send-it ;; Default email send function
  512. smtpmail-default-smtp-server "smtp.gmail.com"
  513. smtpmail-smtp-service 587
  514. )
  515. (defun leo/convert-message-set-point ()
  516. "Set the point to the start of the message body."
  517. (interactive)
  518. (beginning-of-buffer)
  519. (search-forward "--text follows this line--")
  520. (forward-char)
  521. )
  522. (defun leo/convert-message-from-markdown ()
  523. "Convert a markdown flavored mail buffer to html w/mime support."
  524. (interactive)
  525. (if (y-or-n-p "Convert to HTML? ")
  526. ((leo/convert-message-set-point)
  527. (save-excursion
  528. (message-goto-body)
  529. (shell-command-on-region (point) (point-max) "~/.emacs.d/scripts/expand-mime.sh" nil t)))
  530. (message "Aborting."))
  531. )
  532. (setq mu4e-contexts
  533. `(
  534. ;; ,(make-mu4e-context
  535. ;; :name "Vlocity"
  536. ;; :enter-func (lambda () (mu4e-message "Entering Vlocity"))
  537. ;; :leave-func (lambda () (mu4e-message "Leaving Vlocity"))
  538. ;; ;; we match based on the contact-fields of the message
  539. ;; :match-func (lambda (msg)
  540. ;; (when msg
  541. ;; (string= (mu4e-message-field msg :maildir) "/Vlocity")))
  542. ;; :vars '( ( user-mail-address . "lolson@vlocity.com" )
  543. ;; ( smtpmail-mail-address . "lolson@vlocity.com" )
  544. ;; ( smtpmail-smtp-user . "lolson@vlocity.com" )
  545. ;; ( smtpmail-smtp-server . "smtp.gmail.com" )
  546. ;; ( user-full-name . "Levi Olson" )
  547. ;; ( mu4e-compose-signature .
  548. ;; (concat
  549. ;; "Levi Olson\n"
  550. ;; "Senior UI Developer"))
  551. ;; ( mu4e-sent-folder . "/Vlocity/[Gmail].Sent Mail" )
  552. ;; ( mu4e-drafts-folder . "/Vlocity/[Gmail].Drafts" )
  553. ;; ( mu4e-trash-folder . "/Vlocity/[Gmail].Trash" )
  554. ;; ( mu4e-maildir-shortcuts . (("/Vlocity/INBOX" . ?i)
  555. ;; ("/Vlocity/[Gmail].Sent Mail" . ?s)
  556. ;; ("/Vlocity/[Gmail].Trash" . ?t)
  557. ;; ("/Vlocity/[Gmail].All Mail" . ?a)))))
  558. ,(make-mu4e-context
  559. :name "EagleCreek"
  560. :enter-func (lambda () (mu4e-message "Entering EagleCreek"))
  561. :leave-func (lambda () (mu4e-message "Leaving EagleCreek"))
  562. ;; we match based on the contact-fields of the message
  563. :match-func (lambda (msg)
  564. (when msg
  565. (string= (mu4e-message-field msg :maildir) "/eaglecrk")))
  566. :vars '( ( user-mail-address . "lolson@eaglecrk.com" )
  567. ( smtpmail-mail-address . "lolson@eaglecrk.com" )
  568. ( smtpmail-smtp-user . "lolson@eaglecrk.com" )
  569. ( smtpmail-smtp-server . "smtp.office365.com" )
  570. ( user-full-name . "Levi Olson" )
  571. ;; ( mu4e-compose-signature .
  572. ;; (concat
  573. ;; "Levi Olson\n"
  574. ;; "Eagle Creek Software Services\n"
  575. ;; "Senior Application Developer Consultant\n"))
  576. ( mu4e-sent-folder . "/eaglecrk/Sent Items" )
  577. ( mu4e-drafts-folder . "/eaglecrk/Drafts" )
  578. ( mu4e-trash-folder . "/eaglecrk/Deleted Items" )
  579. ( mu4e-maildir-shortcuts . (("/eaglecrk/Inbox" . ?i)
  580. ("/eaglecrk/Sent Items" . ?s)
  581. ("/eaglecrk/Deleted Items" . ?t)
  582. ("/eaglecrk/Archive" . ?a)))))
  583. ;; ,(make-mu4e-context
  584. ;; :name "Gmail"
  585. ;; :enter-func (lambda () (mu4e-message "Entering Gmail"))
  586. ;; :leave-func (lambda () (mu4e-message "Leaving Gmail"))
  587. ;; ;; this matches maildir /Arkham and its sub-directories
  588. ;; :match-func (lambda (msg)
  589. ;; (when msg
  590. ;; (string= (mu4e-message-field msg :maildir) "/Gmail")))
  591. ;; :vars '( ( user-mail-address . "olson.levi@gmail.com" )
  592. ;; ( smtpmail-mail-address . "olson.levi@gmail.com" )
  593. ;; ( smtpmail-smtp-user . "olson.levi@gmail.com" )
  594. ;; ( smtpmail-smtp-server . "smtp.gmail.com" )
  595. ;; ( user-full-name . "Levi Olson" )
  596. ;; ( mu4e-compose-signature .
  597. ;; (concat
  598. ;; "Levi\n"))
  599. ;; ( mu4e-sent-folder . "/Gmail/[Gmail].Sent Mail" )
  600. ;; ( mu4e-drafts-folder . "/Gmail/[Gmail].Drafts" )
  601. ;; ( mu4e-trash-folder . "/Gmail/[Gmail].Trash" )
  602. ;; ( mu4e-maildir-shortcuts . (("/Gmail/INBOX" . ?i)
  603. ;; ("/Gmail/[Gmail].Sent Mail" . ?s)
  604. ;; ("/Gmail/[Gmail].Trash" . ?t)
  605. ;; ("/Gmail/[Gmail].All Mail" . ?a))
  606. ;; )))
  607. ))
  608. ;; Add option to view HTML in browser
  609. (add-to-list 'mu4e-headers-actions
  610. '("in browser" . mu4e-action-view-in-browser) t)
  611. (add-to-list 'mu4e-view-actions
  612. '("in browser" . mu4e-action-view-in-browser) t)
  613. (defun my-message-current-line-cited-p ()
  614. "Indicate whether the line at point is a cited line."
  615. (save-match-data
  616. (string-match (concat "^" message-cite-prefix-regexp)
  617. (buffer-substring (line-beginning-position) (line-end-position)))))
  618. (defun my-message-says-attachment-p ()
  619. "Return t if the message suggests there can be an attachment."
  620. (save-excursion
  621. (goto-char (point-min))
  622. (save-match-data
  623. (let (search-result)
  624. (while
  625. (and (setq search-result (re-search-forward "\\(attach\\|pdf\\|file\\)" nil t))
  626. (my-message-current-line-cited-p)))
  627. search-result))))
  628. (defun my-message-has-attachment-p ()
  629. "Return t if the message has an attachment."
  630. (save-excursion
  631. (goto-char (point-min))
  632. (save-match-data
  633. (re-search-forward "<#part" nil t))))
  634. (defun my-message-pre-send-check-attachment ()
  635. (when (and (my-message-says-attachment-p)
  636. (not (my-message-has-attachment-p)))
  637. (unless
  638. (y-or-n-p "No attachment. Send anyway?")
  639. (error "It seems that an attachment is needed, but none was found. Aborting sending."))))
  640. (add-hook 'message-send-hook 'my-message-pre-send-check-attachment)
  641. (require 'projectile)
  642. (require 'counsel-projectile)
  643. (projectile-mode)
  644. (setq projectile-mode-line '(:eval (format " %s" (projectile-project-name)))
  645. projectile-remember-window-configs t
  646. projectile-completion-system 'ivy)
  647. (counsel-projectile-mode)
  648. ;;; notify.el --- notification front-end
  649. ;; Copyright (C) 2008 Mark A. Hershberger
  650. ;; Original Author: Mark A. Hershberger <mhersberger@intrahealth.org>
  651. ;; Modified by Andrey Kotlarski <m00naticus@gmail.com>
  652. ;; Modified by Andrew Gwozdziewycz <git@apgwoz.com>
  653. ;; Modified by Aidan Gauland <aidalgol@no8wireless.co.nz> October 2011
  654. ;; Modified by Olivier Sirven <the.slaa@gmail.com> November 2013
  655. ;; Keywords: extensions, convenience, lisp
  656. ;; This file is free software; you can redistribute it and/or modify
  657. ;; it under the terms of the GNU General Public License as published by
  658. ;; the Free Software Foundation; either version 2, or (at your option)
  659. ;; any later version.
  660. ;; This file is distributed in the hope that it will be useful,
  661. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  662. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  663. ;; GNU General Public License for more details.
  664. ;; You should have received a copy of the GNU General Public License
  665. ;; along with GNU Emacs; see the file COPYING. If not, write to
  666. ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  667. ;; Boston, MA 02111-1307, USA.
  668. ;;; Commentary:
  669. ;; This provides a single function, `notify', that will produce a notify
  670. ;; pop-up via D-Bus, libnotify, simple message or growl.
  671. ;; To use, just put (autoload 'notify "notify" "Notify TITLE, BODY.")
  672. ;; in your init file. You may override default chosen notification
  673. ;; method by assigning `notify-method' to one of 'notify-via-dbus
  674. ;; 'notify-via-libnotify or 'notify-via-message
  675. ;;; Code:
  676. (defvar notify-defaults (list :app "Emacs" :icon "emacs" :timeout 5000
  677. :urgency "low"
  678. :category "emacs.message")
  679. "Notification settings' defaults.
  680. May be overridden with key-value additional arguments to `notify'.")
  681. (defvar notify-delay '(0 5 0)
  682. "Minimum time allowed between notifications in time format.")
  683. (defvar notify-last-notification '(0 0 0) "Time of last notification.")
  684. (defvar notify-method 'notify-via-growl "Notification method among
  685. 'notify-via-dbus, 'notify-via-libnotify, 'notify-via-message or
  686. 'notify-via-growl")
  687. ;; determine notification method unless already set
  688. ;; prefer growl > D-Bus > libnotify > message
  689. (cond
  690. ((null notify-method)
  691. (setq notify-method
  692. (cond
  693. ((executable-find "growlnotify") 'notify-via-growl)
  694. ((and (require 'dbus nil t)
  695. (dbus-ping :session "org.freedesktop.Notifications"))
  696. (defvar notify-id 0 "Current D-Bus notification id.")
  697. 'notify-via-dbus)
  698. ((executable-find "notify-send") 'notify-via-libnotify)
  699. (t 'notify-via-message))))
  700. ((eq notify-method 'notify-via-dbus) ;housekeeping for pre-chosen DBus
  701. (if (and (require 'dbus nil t)
  702. (dbus-ping :session "org.freedesktop.Notifications"))
  703. (defvar notify-id 0 "Current D-Bus notification id.")
  704. (setq notify-method (if (executable-find "notify-send")
  705. 'notify-via-libnotify
  706. 'notify-via-message))))
  707. ((and (eq notify-method 'notify-via-libnotify)
  708. (not (executable-find "notify-send"))) ;housekeeping for pre-chosen libnotify
  709. (setq notify-method
  710. (if (and (require 'dbus nil t)
  711. (dbus-ping :session "org.freedesktop.Notifications"))
  712. (progn
  713. (defvar notify-id 0 "Current D-Bus notification id.")
  714. 'notify-via-dbus)
  715. 'notify-via-message)))
  716. ((and (eq notify-method 'notify-via-growl)
  717. (not (executable-find "growlnotify")))
  718. (setq notify-method 'notify-via-message)))
  719. (defun notify-via-dbus (title body)
  720. "Send notification with TITLE, BODY `D-Bus'."
  721. (dbus-call-method :session "org.freedesktop.Notifications"
  722. "/org/freedesktop/Notifications"
  723. "org.freedesktop.Notifications" "Notify"
  724. (get 'notify-defaults :app)
  725. (setq notify-id (+ notify-id 1))
  726. (get 'notify-defaults :icon) title body '(:array)
  727. '(:array :signature "{sv}") ':int32
  728. (get 'notify-defaults :timeout)))
  729. (defun notify-via-libnotify (title body)
  730. "Notify with TITLE, BODY via `libnotify'."
  731. (call-process "notify-send" nil 0 nil
  732. title body "-t"
  733. (number-to-string (get 'notify-defaults :timeout))
  734. "-i" (get 'notify-defaults :icon)
  735. "-u" (get 'notify-defaults :urgency)
  736. "-c" (get 'notify-defaults :category)))
  737. (defun notify-via-message (title body)
  738. "Notify TITLE, BODY with a simple message."
  739. (message "%s: %s" title body))
  740. (defun notify-via-growl (title body)
  741. "Notify TITLE, BODY with a growl"
  742. (call-process "growlnotify" nil 0 nil
  743. "-a" (get 'notify-defaults :app)
  744. "-n" (get 'notify-defaults :category)
  745. "-t" (notify-via-growl-stringify title)
  746. "-m" (notify-via-growl-stringify body)))
  747. (defun notify-via-growl-stringify (thing)
  748. (cond ((null thing) "")
  749. ((stringp thing) thing)
  750. (t (format "%s" thing))))
  751. (defun keywords-to-properties (symbol args &optional defaults)
  752. "Add to SYMBOL's property list key-values from ARGS and DEFAULTS."
  753. (when (consp defaults)
  754. (keywords-to-properties symbol defaults))
  755. (while args
  756. (put symbol (car args) (cadr args))
  757. (setq args (cddr args))))
  758. ;;;###autoload
  759. (defun notify (title body &rest args)
  760. "Notify TITLE, BODY via `notify-method'.
  761. ARGS may be amongst :timeout, :icon, :urgency, :app and :category."
  762. (when (time-less-p notify-delay
  763. (time-since notify-last-notification))
  764. (or (eq notify-method 'notify-via-message)
  765. (keywords-to-properties 'notify-defaults args
  766. notify-defaults))
  767. (setq notify-last-notification (current-time))
  768. (funcall notify-method title body)))
  769. (provide 'notify)
  770. ;;; notify.el ends here
  771. (require 'jabber)
  772. (setq jabber-history-enabled t
  773. jabber-use-global-history nil
  774. jabber-backlog-number 40
  775. jabber-backlog-days 30
  776. jabber-alert-presence-message-function (lambda (_who _oldstatus _newstatus _statustext) nil)
  777. )
  778. (setq jabber-account-list '(
  779. ;; ("olson.levi@gmail.com"
  780. ;; (:network-server . "talk.google.com")
  781. ;; (:connection-type . ssl))
  782. ("lolson@vlocity.com"
  783. (:network-server . "talk.google.com")
  784. (:connection-type . ssl))
  785. ))
  786. (defvar my-chat-prompt "[%t] %n>\n" "Customized chat prompt")
  787. (when (featurep 'jabber)
  788. (setq
  789. jabber-chat-foreign-prompt-format my-chat-prompt
  790. jabber-chat-local-prompt-format my-chat-prompt
  791. jabber-groupchat-prompt-format my-chat-prompt
  792. jabber-muc-private-foreign-prompt-format "[%t] %g/%n>\n"
  793. )
  794. )
  795. (defun notify-jabber-notify (from buf text _proposed-alert)
  796. "(jabber.el hook) Notify of new Jabber chat messages via notify.el"
  797. (when (or jabber-message-alert-same-buffer
  798. (not (memq (selected-window) (get-buffer-window-list buf))))
  799. (if (jabber-muc-sender-p from)
  800. (notify (format "(PM) %s"
  801. (jabber-jid-displayname (jabber-jid-user from)))
  802. (format "%s: %s" (jabber-jid-resource from) text)))
  803. (notify (format "%s" (jabber-jid-displayname from))
  804. text)))
  805. ;; (add-hook 'jabber-alert-message-hooks 'notify-jabber-notify)
  806. ;; (require 'autosmiley)
  807. ;; (add-hook 'jabber-chat-mode-hook 'autosmiley-mode)
  808. (defun jabber ()
  809. (interactive)
  810. (jabber-connect-all)
  811. (switch-to-buffer "*-jabber-roster-*"))
  812. (defun hyperspace-action->mu4e (&optional query)
  813. "Search mu4e with QUERY.
  814. If QUERY is unspecified, use the first bookmark in variable
  815. mu4e-bookmarks and update mail and index."
  816. (mu4e-headers-search (or query (caar mu4e-bookmarks)))
  817. (unless query
  818. (mu4e-update-mail-and-index nil)))
  819. (add-to-list 'hyperspace-actions '("m4" . hyperspace-action->mu4e))
  820. (defun hyperspace-action->elfeed (&optional query)
  821. "Load elfeed, optionally searching for QUERY."
  822. (elfeed)
  823. (if query
  824. (elfeed-search-set-filter query)
  825. (elfeed-search-fetch nil)))
  826. (add-to-list 'hyperspace-actions '("lf" . hyperspace-action->elfeed))
  827. (require 'rainbow-delimiters)
  828. (global-flycheck-mode)
  829. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  830. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  831. (setq-default indent-tabs-mode nil
  832. tab-width 4)
  833. (defvaralias 'c-basic-offset 'tab-width)
  834. (defvaralias 'cperl-indent-level 'tab-width)
  835. (electric-pair-mode 1)
  836. (show-paren-mode 1)
  837. (require 'dockerfile-mode)
  838. (add-to-list 'auto-mode-alist '("Dockerfile*\\'" . dockerfile-mode))
  839. (require 'gitignore-mode)
  840. (add-to-list 'auto-mode-alist '("gitignore\\'" . gitignore-mode))
  841. (require 'json-mode)
  842. (add-to-list 'auto-mode-alist '("\\.json\\'" . json-mode))
  843. (require 'web-mode)
  844. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  845. (elpy-enable)
  846. (setq python-shell-interpreter "jupyter"
  847. python-shell-interpreter-args "console --simple-prompt")
  848. (when (require 'flycheck nil t)
  849. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  850. (add-hook 'elpy-mode-hook 'flycheck-mode))
  851. (require 'py-autopep8)
  852. (setq py-autopep8-options '("--ignore=E501"))
  853. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
  854. (require 'go-mode)
  855. (require 'go-playground)
  856. (require 'gorepl-mode)
  857. (require 'company-go)
  858. (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))
  859. (add-hook 'go-mode-hook (lambda ()
  860. (add-hook 'before-save-hook 'gofmt-before-save)
  861. (local-set-key (kbd "M-.") 'godef-jump)
  862. (local-set-key (kbd "M-,") 'pop-tag-mark)
  863. (local-set-key (kbd "C-c C-c") (lambda ()
  864. (interactive)
  865. (ansi-term)
  866. (comint-send-string "*ansi-term*" "make\n")))
  867. (set (make-local-variable 'company-backends) '(company-go))
  868. (setq company-tooltip-limit 20
  869. company-echo-delay 0
  870. company-begin-commands '(self-insert-command))
  871. (gorepl-mode)))
  872. (defun set-exec-path-from-shell-PATH ()
  873. (let ((path-from-shell (replace-regexp-in-string
  874. "[ \t\n]*$"
  875. ""
  876. (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
  877. (setenv "PATH" path-from-shell)
  878. (setq eshell-path-env path-from-shell)
  879. (setq exec-path (split-string path-from-shell path-separator))))
  880. (when window-system (set-exec-path-from-shell-PATH))
  881. (setenv "GOPATH" "/Users/leviolson/go")
  882. (add-to-list 'exec-path "/Users/leviolson/go/bin")
  883. (defun setup-tide-mode ()
  884. "Tide setup function."
  885. (interactive)
  886. (tide-setup)
  887. (flycheck-mode +1)
  888. (setq flycheck-check-syntax-automatically '(save mode-enabled))
  889. (eldoc-mode +1)
  890. (tide-hl-identifier-mode +1)
  891. (company-mode +1))
  892. ;; aligns annotation to the right hand side
  893. (setq company-tooltip-align-annotations t)
  894. ;; formats the buffer before saving
  895. (add-hook 'before-save-hook 'tide-format-before-save)
  896. (add-hook 'typescript-mode-hook #'setup-tide-mode)
  897. (require 'typescript-mode)
  898. (require 'tide)
  899. (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
  900. (add-hook 'typescript-mode-hook
  901. '(lambda ()
  902. (set (make-local-variable 'company-backends) '(company-tide))
  903. (setq company-tooltip-limit 20
  904. company-echo-delay 0
  905. company-begin-commands '(self-insert-command)
  906. tide-format-options '(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t :placeOpenBraceOnNewLineForFunctions nil))
  907. (tide-setup)))
  908. (require 'web-mode)
  909. (add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
  910. (add-hook 'web-mode-hook
  911. (lambda ()
  912. (when (string-equal "tsx" (file-name-extension buffer-file-name))
  913. (setup-tide-mode))))
  914. ;; enable typescript-tslint checker
  915. (flycheck-add-mode 'typescript-tslint 'web-mode)
  916. (require 'web-mode)
  917. (add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
  918. (add-hook 'web-mode-hook
  919. (lambda ()
  920. (when (string-equal "jsx" (file-name-extension buffer-file-name))
  921. (setup-tide-mode))))
  922. ;; configure jsx-tide checker to run after your default jsx checker
  923. (flycheck-add-mode 'javascript-eslint 'web-mode)
  924. (flycheck-add-next-checker 'javascript-eslint 'jsx-tide 'append)
  925. (org-babel-do-load-languages
  926. 'org-babel-load-languages
  927. '((js . t)
  928. (shell . t)
  929. (emacs-lisp . t)))
  930. (setq org-todo-keywords
  931. '((sequence "TODO(t)" "|" "DONE(d)")
  932. (sequence "BUG(b)" "|" "INPROGRESS(i)" "FIXED(f)")
  933. (sequence "|" "CANCELED(c)")
  934. (sequence "|" "NEEDCLARIFICATION(n)")
  935. (sequence "|" "PROVIDEUPDATE(p)")
  936. (sequence "|" "WAITING(w)")
  937. ))
  938. (setq org-agenda-files
  939. '("~/Dropbox/Org/todo.org" "~/Dropbox/Org/archive.org"))
  940. (setq org-refile-targets
  941. '((nil :maxlevel . 1)
  942. (org-agenda-files :maxlevel . 1)))
  943. (add-hook 'focus-in-hook
  944. (lambda () (progn
  945. (setq org-tags-column (- 5 (frame-width)))) (org-align-all-tags)))
  946. (add-hook 'focus-out-hook
  947. (lambda () (progn
  948. (setq org-tags-column (- 5 (frame-width)))) (org-align-all-tags)))
  949. (defvar org-src-tab-acts-natively)
  950. (setq org-src-tab-acts-natively t)
  951. ;; (setenv "NODE_PATH"
  952. ;; (getenv "NODE_PATH"))
  953. (defvar org-confirm-babel-evaluate)
  954. (defun my-org-confirm-babel-evaluate (lang _body)
  955. "Execute certain languages without confirming.
  956. Takes LANG to allow and BODY to execute."
  957. (not (or (string= lang "js")
  958. (string= lang "restclient")
  959. (string= lang "emacs-lisp")
  960. (string= lang "shell"))))
  961. (setq org-confirm-babel-evaluate #'my-org-confirm-babel-evaluate)
  962. (add-to-list 'org-structure-template-alist
  963. (list "e" (concat "#+BEGIN_SRC emacs-lisp :results silent\n"
  964. "\n"
  965. "#+END_SRC")))
  966. (add-to-list 'org-structure-template-alist
  967. (list "j" (concat "#+BEGIN_SRC js :cmd \"babel-node\"\n"
  968. "\n"
  969. "#+END_SRC")))
  970. (add-to-list 'org-structure-template-alist
  971. (list "r" (concat "#+BEGIN_SRC restclient :results raw\n"
  972. "\n"
  973. "#+END_SRC")))
  974. ;;store org-mode links to messages
  975. (require 'org-mu4e)
  976. ;;store link to message if in header view, not to header query
  977. (setq org-mu4e-link-query-in-headers-mode nil)
  978. (setq org-capture-templates
  979. '(("t" "todo" entry (file+headline "~/todo.org" "Tasks")
  980. "* TODO [#A] %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n%a\n")))
  981. (elfeed-org)
  982. (setq rmh-elfeed-org-files (list "~/Dropbox/Org/elfeed.org"))
  983. (defun leo/elfeed-search (arg)
  984. "Search for ARG in feed."
  985. (interactive)
  986. (elfeed-search-set-filter arg))
  987. (define-key elfeed-search-mode-map "a" (lambda () (interactive) (leo/elfeed-search "")))
  988. (define-key elfeed-search-mode-map "e" (lambda () (interactive) (leo/elfeed-search "+emacs")))
  989. (define-key elfeed-search-mode-map "d" (lambda () (interactive) (leo/elfeed-search "+daily")))
  990. (define-key elfeed-search-mode-map "x" (lambda () (interactive) (leo/elfeed-search "xkcd")))
  991. (defun find-user-init-file ()
  992. "Edit the `~/.emacs.d/init.org' file."
  993. (interactive)
  994. (find-file "~/.emacs.d/init.org"))
  995. (defun find-todo-file ()
  996. "Edit the `~/todo.org' file."
  997. (interactive)
  998. (find-file "~/Dropbox/Org/todo.org"))
  999. (defun load-user-init-file ()
  1000. "LO: Reload the `~/.emacs.d/init.elc' file."
  1001. (interactive)
  1002. (load-file "~/.emacs.d/init.elc"))
  1003. (defun jump-to-symbol-internal (&optional backwardp)
  1004. "Jumps to the next symbol near the point if such a symbol exists. If BACKWARDP is non-nil it jumps backward."
  1005. (let* ((point (point))
  1006. (bounds (find-tag-default-bounds))
  1007. (beg (car bounds)) (end (cdr bounds))
  1008. (str (isearch-symbol-regexp (find-tag-default)))
  1009. (search (if backwardp 'search-backward-regexp
  1010. 'search-forward-regexp)))
  1011. (goto-char (if backwardp beg end))
  1012. (funcall search str nil t)
  1013. (cond ((<= beg (point) end) (goto-char point))
  1014. (backwardp (forward-char (- point beg)))
  1015. (t (backward-char (- end point))))))
  1016. (defun jump-to-previous-like-this ()
  1017. "Jumps to the previous occurrence of the symbol at point."
  1018. (interactive)
  1019. (jump-to-symbol-internal t))
  1020. (defun jump-to-next-like-this ()
  1021. "Jumps to the next occurrence of the symbol at point."
  1022. (interactive)
  1023. (jump-to-symbol-internal))
  1024. (defun match-paren (arg)
  1025. "Go to the matching paren if on a paren; otherwise insert ARG (a literal % sign)."
  1026. (interactive "p")
  1027. (cond ((looking-at "\\s(") (forward-list 1))
  1028. ((looking-back "\\s(" 2) (backward-char 1) (forward-list 1))
  1029. ((looking-at "\\s)") (forward-char 1) (backward-list 1))
  1030. ((looking-back "\\s)" 2) (backward-list 1))
  1031. (t (self-insert-command (or arg 1)))))
  1032. (defun kill-this-buffer-unless-scratch ()
  1033. "Works like `kill-this-buffer' unless the current buffer is the *scratch* buffer. In which case the buffer content is deleted and the buffer is buried."
  1034. (interactive)
  1035. (if (not (string= (buffer-name) "*scratch*"))
  1036. (kill-this-buffer)
  1037. (delete-region (point-min) (point-max))
  1038. (switch-to-buffer (other-buffer))
  1039. (bury-buffer "*scratch*")))
  1040. (defun delete-backward-sentence ()
  1041. "LO: Delete to the beginning of the sentence/line."
  1042. (interactive)
  1043. (delete-region (point) (progn (backward-sentence) (point))))
  1044. (defun delete-backward-to-boundary (arg)
  1045. "LO: Delete backward to the previous word boundary. With ARG, do this many times."
  1046. (interactive "p")
  1047. (let ((a (point))
  1048. (b (progn
  1049. (backward-word arg)
  1050. (forward-word)
  1051. (point))))
  1052. (if (< a b)
  1053. (delete-region a (progn (backward-word arg) (point)))
  1054. (if (= a b)
  1055. (delete-region a (progn (backward-word arg) (point)))
  1056. (delete-region a b)))))
  1057. (defun comment-or-uncomment-region-or-line ()
  1058. "Comments or uncomments the region or the current line if there's no active region."
  1059. (interactive)
  1060. (let (beg end)
  1061. (if (region-active-p)
  1062. (setq beg (region-beginning) end (region-end))
  1063. (setq beg (line-beginning-position) end (line-end-position)))
  1064. (comment-or-uncomment-region beg end)))
  1065. (defun fold-toggle (column)
  1066. "Code folding by COLUMN."
  1067. (interactive "P")
  1068. (set-selective-display
  1069. (or column
  1070. (unless selective-display
  1071. (1+ (current-column))))))
  1072. (defun new-line-below ()
  1073. "LO: Create a new line below current line."
  1074. (interactive)
  1075. (move-end-of-line 1)
  1076. (newline-and-indent))
  1077. (defun new-line-above ()
  1078. "LO: Create a new line above current line."
  1079. (interactive)
  1080. (move-beginning-of-line 1)
  1081. (newline)
  1082. (forward-line -1))
  1083. (defun duplicate-thing (comment)
  1084. "LO: Duplicates the current line, or the region if active. If an argument (COMMENT) is given, the duplicated region will be commented out."
  1085. (interactive "P")
  1086. (save-excursion
  1087. (let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
  1088. (end (if (region-active-p) (region-end) (point-at-eol))))
  1089. (goto-char end)
  1090. (unless (region-active-p)
  1091. (newline))
  1092. (insert (buffer-substring start end))
  1093. (when comment (comment-region start end)))))
  1094. (defun tidy ()
  1095. "LO: Ident, untabify and unwhitespacify current buffer, or region if active."
  1096. (interactive)
  1097. (let ((beg (if (region-active-p) (region-beginning) (point-min)))
  1098. (end (if (region-active-p) (region-end) (point-max))))
  1099. (let ((inhibit-message t))
  1100. (indent-region beg end))
  1101. (whitespace-cleanup)
  1102. (untabify beg (if (< end (point-max)) end (point-max)))
  1103. (if (region-active-p) (message "Indenting Region...Done") (message "Indenting File...Done"))))
  1104. (defun phil-columns ()
  1105. "LO: Good 'ol Phil-Columns."
  1106. (interactive)
  1107. (message "Good 'ol fill-columns")
  1108. (with-output-to-temp-buffer "*PHIL-COLUMN*"
  1109. (shell-command "mpv --no-video 'https://www.youtube.com/watch?v=YkADj0TPrJA&t=3m16s' > /dev/null 2>&1 & sleep 8; pkill mpv"))
  1110. (other-window 1)
  1111. (delete-window))
  1112. (declare-function first "Goto FIRST shell.")
  1113. (declare-function goto-non-shell-buffer "Goto something other than a shell buffer.")
  1114. (declare-function switch-shell "Switch shell.")
  1115. (let ((last-shell ""))
  1116. (defun toggle-shell ()
  1117. (interactive)
  1118. (cond ((string-match-p "^\\*shell<[1-9][0-9]*>\\*$" (buffer-name))
  1119. (goto-non-shell-buffer))
  1120. ((get-buffer last-shell) (switch-to-buffer last-shell))
  1121. (t (shell (setq last-shell "*shell<1>*")))))
  1122. (defun switch-shell (n)
  1123. (let ((buffer-name (format "*shell<%d>*" n)))
  1124. (setq last-shell buffer-name)
  1125. (cond ((get-buffer buffer-name)
  1126. (switch-to-buffer buffer-name))
  1127. (t (shell buffer-name)
  1128. (rename-buffer buffer-name)))))
  1129. (defun goto-non-shell-buffer ()
  1130. (let* ((r "^\\*shell<[1-9][0-9]*>\\*$")
  1131. (shell-buffer-p (lambda (b) (string-match-p r (buffer-name b))))
  1132. (non-shells (cl-remove-if shell-buffer-p (buffer-list))))
  1133. (when non-shells
  1134. (switch-to-buffer (first non-shells))))))
  1135. (defadvice shell (after kill-with-no-query nil activate)
  1136. "."
  1137. (set-process-query-on-exit-flag (get-buffer-process ad-return-value) nil))
  1138. (declare-function comint-truncate-buffer ".")
  1139. (defun clear-comint ()
  1140. "Run `comint-truncate-buffer' with the `comint-buffer-maximum-size' set to zero."
  1141. (interactive)
  1142. (let ((comint-buffer-maximum-size 0))
  1143. (comint-truncate-buffer)))
  1144. (defun c-setup ()
  1145. "Compile."
  1146. (local-set-key (kbd "C-c C-c") 'compile))
  1147. (require 'company)
  1148. (add-hook 'comint-mode-hook (lambda () (local-set-key (kbd "c-l") 'clear-comint)))
  1149. (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
  1150. (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
  1151. (add-hook 'c-mode-common-hook 'c-setup)
  1152. (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
  1153. (defvar company-active-map (make-keymap)
  1154. "company mode keymap.")
  1155. (defvar custom-bindings (make-keymap)
  1156. "a keymap of custom bindings.")
  1157. (define-key custom-bindings (kbd "M-p") 'jump-to-previous-like-this)
  1158. (define-key custom-bindings (kbd "M-n") 'jump-to-next-like-this)
  1159. (define-key custom-bindings (kbd "M-<tab>") 'switch-to-next-buffer)
  1160. (define-key custom-bindings (kbd "M-<backspace>")'delete-backward-to-boundary)
  1161. (define-key custom-bindings (kbd "C-<backspace>")'delete-backward-to-boundary)
  1162. (define-key custom-bindings (kbd "C-}") 'mc/mark-next-like-this)
  1163. (define-key custom-bindings (kbd "C-)") 'mc/unmark-next-like-this)
  1164. (define-key custom-bindings (kbd "C-{") 'mc/mark-previous-like-this)
  1165. (define-key custom-bindings (kbd "C-(") 'mc/unmark-previous-like-this)
  1166. (define-key custom-bindings (kbd "C-'") 'mc-hide-unmatched-lines-mode)
  1167. (define-key custom-bindings (kbd "C-c 1") 'mc/insert-numbers)
  1168. (define-key custom-bindings (kbd "C-c s") 'mc/sort-regions)
  1169. (define-key custom-bindings "%" 'match-paren)
  1170. (define-key custom-bindings (kbd "C-x .") 'dash-at-point)
  1171. (define-key custom-bindings (kbd "C-x ,") 'dash-at-point-with-docset)
  1172. (define-key custom-bindings (kbd "C-s") (lambda () (interactive) (swiper (format "%s" (thing-at-point 'symbol)))))
  1173. (define-key custom-bindings (kbd "C-x C-l m") 'mu4e)
  1174. (define-key custom-bindings (kbd "C-x C-o t") 'find-todo-file)
  1175. (define-key custom-bindings (kbd "C-x C-l j") 'jabber)
  1176. (define-key custom-bindings (kbd "C-x C-l f") 'elfeed)
  1177. (define-key custom-bindings (kbd "C-x C-l a") 'org-agenda)
  1178. (define-key custom-bindings (kbd "C-x C-l c") 'calendar)
  1179. (define-key custom-bindings (kbd "M-SPC") #'hyperspace)
  1180. ;; (dolist (n (number-sequence 1 9))
  1181. ;; (global-set-key (kbd (concat "M-" (int-to-string n)))
  1182. ;; (lambda () (interactive) (switch-shell n))))
  1183. (define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)
  1184. (define-key company-active-map (kbd "C-n") 'company-select-next)
  1185. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  1186. (define-key company-active-map (kbd "<tab>") 'company-complete)
  1187. (define-key custom-bindings (kbd "C-c p") 'counsel-projectile-switch-project)
  1188. (define-key custom-bindings (kbd "C-c f") 'counsel-projectile-find-file)
  1189. (define-key custom-bindings (kbd "C-c m") 'magit-status)
  1190. (define-key custom-bindings (kbd "C-c D") 'define-word-at-point)
  1191. (define-key custom-bindings (kbd "C-@") 'er/expand-region)
  1192. (define-key custom-bindings (kbd "C-#") 'er/contract-region)
  1193. (define-key custom-bindings (kbd "C-S-c C-S-c") 'mc/edit-lines)
  1194. (define-key custom-bindings (kbd "C-c b") 'ivy-switch-buffer)
  1195. (define-key custom-bindings (kbd "C-c l") 'org-store-link)
  1196. (define-key custom-bindings (kbd "C-c t") 'org-set-tags)
  1197. (define-key custom-bindings (kbd "M-u") 'upcase-dwim)
  1198. (define-key custom-bindings (kbd "M-c") 'capitalize-dwim)
  1199. (define-key custom-bindings (kbd "M-l") 'downcase-dwim)
  1200. (define-key custom-bindings (kbd "M-o") 'other-window)
  1201. (define-key custom-bindings (kbd "C-c s") 'ispell-word)
  1202. (define-key custom-bindings (kbd "C-c C-d") 'org-capture)
  1203. (define-key custom-bindings (kbd "C-c <up>") 'windmove-up)
  1204. (define-key custom-bindings (kbd "C-c <down>") 'windmove-down)
  1205. (define-key custom-bindings (kbd "C-c <left>") 'windmove-left)
  1206. (define-key custom-bindings (kbd "C-c <right>") 'windmove-right)
  1207. (define-key custom-bindings (kbd "C-c a") (lambda () (interactive) (org-agenda nil "n")))
  1208. (define-key custom-bindings (kbd "C-c e") 'find-user-init-file)
  1209. (define-key custom-bindings (kbd "C-x f") 'phil-columns)
  1210. (define-key custom-bindings (kbd "C-x k") 'kill-this-buffer-unless-scratch)
  1211. (define-key custom-bindings (kbd "C-c d") 'duplicate-thing)
  1212. (define-key custom-bindings (kbd "C-c c") 'comment-or-uncomment-region-or-line)
  1213. (define-key custom-bindings (kbd "C-;") 'comment-or-uncomment-region-or-line)
  1214. (define-key custom-bindings (kbd "C-o") 'new-line-below)
  1215. (define-key custom-bindings (kbd "C-S-o") 'new-line-above)
  1216. (define-key custom-bindings (kbd "<C-tab>") 'tidy)
  1217. (define-key custom-bindings (kbd "M-q") 'kill-this-buffer)
  1218. (define-key custom-bindings (kbd "M-RET") '(lambda () (interactive) (term (getenv "SHELL"))))
  1219. (define-minor-mode custom-bindings-mode
  1220. "A mode that activates custom-bindings."
  1221. t nil custom-bindings)
  1222. (cond ((member "PragmataPro Mono Liga" (font-family-list))
  1223. (set-face-attribute 'default nil :font "PragmataPro Mono Liga-13")))
  1224. (require 'doom-modeline)
  1225. (doom-modeline-mode 1)
  1226. ;; How tall the mode-line should be (only respected in GUI Emacs).
  1227. (setq doom-modeline-height 30)
  1228. ;; How wide the mode-line bar should be (only respected in GUI Emacs).
  1229. (setq doom-modeline-bar-width 4)
  1230. ;; Determines the style used by `doom-modeline-buffer-file-name'.
  1231. ;;
  1232. ;; Given ~/Projects/FOSS/emacs/lisp/comint.el
  1233. ;; truncate-upto-project => ~/P/F/emacs/lisp/comint.el
  1234. ;; truncate-from-project => ~/Projects/FOSS/emacs/l/comint.el
  1235. ;; truncate-with-project => emacs/l/comint.el
  1236. ;; truncate-except-project => ~/P/F/emacs/l/comint.el
  1237. ;; truncate-upto-root => ~/P/F/e/lisp/comint.el
  1238. ;; truncate-all => ~/P/F/e/l/comint.el
  1239. ;; relative-from-project => emacs/lisp/comint.el
  1240. ;; relative-to-project => lisp/comint.el
  1241. ;; file-name => comint.el
  1242. ;; buffer-name => comint.el<2> (uniquify buffer name)
  1243. ;;
  1244. ;; If you are expereicing the laggy issue, especially while editing remote files
  1245. ;; with tramp, please try `file-name' style.
  1246. ;; Please refer to https://github.com/bbatsov/projectile/issues/657.
  1247. (setq doom-modeline-buffer-file-name-style 'truncate-upto-project)
  1248. ;; What executable of Python will be used (if nil nothing will be showed).
  1249. (setq doom-modeline-python-executable "python")
  1250. ;; Whether show `all-the-icons' or not (if nil nothing will be showed).
  1251. (setq doom-modeline-icon t)
  1252. ;; Whether show the icon for major mode. It respects `doom-modeline-icon'.
  1253. (setq doom-modeline-major-mode-icon t)
  1254. ;; Display color icons for `major-mode'. It respects `all-the-icons-color-icons'.
  1255. (setq doom-modeline-major-mode-color-icon nil)
  1256. ;; Whether display minor modes or not. Non-nil to display in mode-line.
  1257. (setq doom-modeline-minor-modes nil)
  1258. ;; If non-nil, a word count will be added to the selection-info modeline segment.
  1259. (setq doom-modeline-enable-word-count nil)
  1260. ;; If non-nil, only display one number for checker information if applicable.
  1261. (setq doom-modeline-checker-simple-format t)
  1262. ;; Whether display perspective name or not. Non-nil to display in mode-line.
  1263. (setq doom-modeline-persp-name t)
  1264. ;; Whether display `lsp' state or not. Non-nil to display in mode-line.
  1265. (setq doom-modeline-lsp t)
  1266. ;; Whether display github notifications or not. Requires `ghub` package.
  1267. (setq doom-modeline-github nil)
  1268. ;; The interval of checking github.
  1269. (setq doom-modeline-github-interval (* 30 60))
  1270. ;; Whether display environment version or not.
  1271. (setq doom-modeline-env-version t)
  1272. ;; Whether display mu4e notifications or not. Requires `mu4e-alert' package.
  1273. (setq doom-modeline-mu4e t)