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. (setq mu4e-maildir "~/Mail"
  492. mu4e-mu-binary "/usr/local/bin/mu"
  493. mu4e-change-filenames-when-moving t ;; Rename files when moving (required by mbsync)
  494. mu4e-compose-in-new-frame t ;; New compose gets new frame
  495. mu4e-context-policy 'pick-first
  496. mu4e-get-mail-command "mbsync -a" ;; MBSYNC is the mail cmd
  497. mu4e-html2text-command "/usr/local/bin/w3m -T text/html" ;; HTML to text command
  498. mu4e-headers-include-related nil ;; Stop threading in INBOX
  499. mu4e-sent-messages-behavior 'delete ;; Delete sent messages
  500. mu4e-update-interval 300 ;; 5 mins
  501. mu4e-use-fancy-chars t ;; use 'fancy' chars
  502. mu4e-user-mail-address-list '("lolson@eaglecrk.com"
  503. "lolson@vlocity.com"
  504. "olson.levi@gmail.com")
  505. mu4e-view-show-images t ;; attempt to show images
  506. mu4e-view-image-max-width 400 ;; max image size
  507. message-citation-line-format "On %a %d %b %Y at %R, %f wrote:\n" ;; customize the reply-quote-string
  508. message-citation-line-function 'message-insert-formatted-citation-line ;; choose to use the formatted string
  509. message-kill-buffer-on-exit t ;; don't keep messages around
  510. send-mail-function 'smtpmail-send-it ;; Default email send function
  511. smtpmail-default-smtp-server "smtp.gmail.com"
  512. smtpmail-smtp-service 587
  513. )
  514. (defun leo/convert-message-set-point ()
  515. "Set the point to the start of the message body."
  516. (interactive)
  517. (beginning-of-buffer)
  518. (search-forward "--text follows this line--")
  519. (forward-char)
  520. )
  521. (defun leo/convert-message-from-markdown ()
  522. "Convert a markdown flavored mail buffer to html w/mime support."
  523. (interactive)
  524. (if (y-or-n-p "Convert to HTML? ")
  525. ((leo/convert-message-set-point)
  526. (save-excursion
  527. (message-goto-body)
  528. (shell-command-on-region (point) (point-max) "~/.emacs.d/scripts/expand-mime.sh" nil t)))
  529. (message "Aborting."))
  530. )
  531. (setq mu4e-contexts
  532. `(
  533. ;; ,(make-mu4e-context
  534. ;; :name "Vlocity"
  535. ;; :enter-func (lambda () (mu4e-message "Entering Vlocity"))
  536. ;; :leave-func (lambda () (mu4e-message "Leaving Vlocity"))
  537. ;; ;; we match based on the contact-fields of the message
  538. ;; :match-func (lambda (msg)
  539. ;; (when msg
  540. ;; (string= (mu4e-message-field msg :maildir) "/Vlocity")))
  541. ;; :vars '( ( user-mail-address . "lolson@vlocity.com" )
  542. ;; ( smtpmail-mail-address . "lolson@vlocity.com" )
  543. ;; ( smtpmail-smtp-user . "lolson@vlocity.com" )
  544. ;; ( smtpmail-smtp-server . "smtp.gmail.com" )
  545. ;; ( user-full-name . "Levi Olson" )
  546. ;; ( mu4e-compose-signature .
  547. ;; (concat
  548. ;; "Levi Olson\n"
  549. ;; "Senior UI Developer"))
  550. ;; ( mu4e-sent-folder . "/Vlocity/[Gmail].Sent Mail" )
  551. ;; ( mu4e-drafts-folder . "/Vlocity/[Gmail].Drafts" )
  552. ;; ( mu4e-trash-folder . "/Vlocity/[Gmail].Trash" )
  553. ;; ( mu4e-maildir-shortcuts . (("/Vlocity/INBOX" . ?i)
  554. ;; ("/Vlocity/[Gmail].Sent Mail" . ?s)
  555. ;; ("/Vlocity/[Gmail].Trash" . ?t)
  556. ;; ("/Vlocity/[Gmail].All Mail" . ?a)))))
  557. ,(make-mu4e-context
  558. :name "EagleCreek"
  559. :enter-func (lambda () (mu4e-message "Entering EagleCreek"))
  560. :leave-func (lambda () (mu4e-message "Leaving EagleCreek"))
  561. ;; we match based on the contact-fields of the message
  562. :match-func (lambda (msg)
  563. (when msg
  564. (string= (mu4e-message-field msg :maildir) "/eaglecrk")))
  565. :vars '( ( user-mail-address . "lolson@eaglecrk.com" )
  566. ( smtpmail-mail-address . "lolson@eaglecrk.com" )
  567. ( smtpmail-smtp-user . "lolson@eaglecrk.com" )
  568. ( smtpmail-smtp-server . "smtp.office365.com" )
  569. ( user-full-name . "Levi Olson" )
  570. ;; ( mu4e-compose-signature .
  571. ;; (concat
  572. ;; "Levi Olson\n"
  573. ;; "Eagle Creek Software Services\n"
  574. ;; "Senior Application Developer Consultant\n"))
  575. ( mu4e-sent-folder . "/eaglecrk/Sent Items" )
  576. ( mu4e-drafts-folder . "/eaglecrk/Drafts" )
  577. ( mu4e-trash-folder . "/eaglecrk/Deleted Items" )
  578. ( mu4e-maildir-shortcuts . (("/eaglecrk/Inbox" . ?i)
  579. ("/eaglecrk/Sent Items" . ?s)
  580. ("/eaglecrk/Deleted Items" . ?t)
  581. ("/eaglecrk/Archive" . ?a)))))
  582. ;; ,(make-mu4e-context
  583. ;; :name "Gmail"
  584. ;; :enter-func (lambda () (mu4e-message "Entering Gmail"))
  585. ;; :leave-func (lambda () (mu4e-message "Leaving Gmail"))
  586. ;; ;; this matches maildir /Arkham and its sub-directories
  587. ;; :match-func (lambda (msg)
  588. ;; (when msg
  589. ;; (string= (mu4e-message-field msg :maildir) "/Gmail")))
  590. ;; :vars '( ( user-mail-address . "olson.levi@gmail.com" )
  591. ;; ( smtpmail-mail-address . "olson.levi@gmail.com" )
  592. ;; ( smtpmail-smtp-user . "olson.levi@gmail.com" )
  593. ;; ( smtpmail-smtp-server . "smtp.gmail.com" )
  594. ;; ( user-full-name . "Levi Olson" )
  595. ;; ( mu4e-compose-signature .
  596. ;; (concat
  597. ;; "Levi\n"))
  598. ;; ( mu4e-sent-folder . "/Gmail/[Gmail].Sent Mail" )
  599. ;; ( mu4e-drafts-folder . "/Gmail/[Gmail].Drafts" )
  600. ;; ( mu4e-trash-folder . "/Gmail/[Gmail].Trash" )
  601. ;; ( mu4e-maildir-shortcuts . (("/Gmail/INBOX" . ?i)
  602. ;; ("/Gmail/[Gmail].Sent Mail" . ?s)
  603. ;; ("/Gmail/[Gmail].Trash" . ?t)
  604. ;; ("/Gmail/[Gmail].All Mail" . ?a))
  605. ;; )))
  606. ))
  607. ;; Add option to view HTML in browser
  608. (add-to-list 'mu4e-headers-actions
  609. '("in browser" . mu4e-action-view-in-browser) t)
  610. (add-to-list 'mu4e-view-actions
  611. '("in browser" . mu4e-action-view-in-browser) t)
  612. (defun my-message-current-line-cited-p ()
  613. "Indicate whether the line at point is a cited line."
  614. (save-match-data
  615. (string-match (concat "^" message-cite-prefix-regexp)
  616. (buffer-substring (line-beginning-position) (line-end-position)))))
  617. (defun my-message-says-attachment-p ()
  618. "Return t if the message suggests there can be an attachment."
  619. (save-excursion
  620. (goto-char (point-min))
  621. (save-match-data
  622. (let (search-result)
  623. (while
  624. (and (setq search-result (re-search-forward "\\(attach\\|pdf\\|file\\)" nil t))
  625. (my-message-current-line-cited-p)))
  626. search-result))))
  627. (defun my-message-has-attachment-p ()
  628. "Return t if the message has an attachment."
  629. (save-excursion
  630. (goto-char (point-min))
  631. (save-match-data
  632. (re-search-forward "<#part" nil t))))
  633. (defun my-message-pre-send-check-attachment ()
  634. (when (and (my-message-says-attachment-p)
  635. (not (my-message-has-attachment-p)))
  636. (unless
  637. (y-or-n-p "No attachment. Send anyway?")
  638. (error "It seems that an attachment is needed, but none was found. Aborting sending."))))
  639. (add-hook 'message-send-hook 'my-message-pre-send-check-attachment)
  640. (require 'projectile)
  641. (require 'counsel-projectile)
  642. (projectile-mode)
  643. (setq projectile-mode-line '(:eval (format " %s" (projectile-project-name)))
  644. projectile-remember-window-configs t
  645. projectile-completion-system 'ivy)
  646. (counsel-projectile-mode)
  647. ;;; notify.el --- notification front-end
  648. ;; Copyright (C) 2008 Mark A. Hershberger
  649. ;; Original Author: Mark A. Hershberger <mhersberger@intrahealth.org>
  650. ;; Modified by Andrey Kotlarski <m00naticus@gmail.com>
  651. ;; Modified by Andrew Gwozdziewycz <git@apgwoz.com>
  652. ;; Modified by Aidan Gauland <aidalgol@no8wireless.co.nz> October 2011
  653. ;; Modified by Olivier Sirven <the.slaa@gmail.com> November 2013
  654. ;; Keywords: extensions, convenience, lisp
  655. ;; This file is free software; you can redistribute it and/or modify
  656. ;; it under the terms of the GNU General Public License as published by
  657. ;; the Free Software Foundation; either version 2, or (at your option)
  658. ;; any later version.
  659. ;; This file is distributed in the hope that it will be useful,
  660. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  661. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  662. ;; GNU General Public License for more details.
  663. ;; You should have received a copy of the GNU General Public License
  664. ;; along with GNU Emacs; see the file COPYING. If not, write to
  665. ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  666. ;; Boston, MA 02111-1307, USA.
  667. ;;; Commentary:
  668. ;; This provides a single function, `notify', that will produce a notify
  669. ;; pop-up via D-Bus, libnotify, simple message or growl.
  670. ;; To use, just put (autoload 'notify "notify" "Notify TITLE, BODY.")
  671. ;; in your init file. You may override default chosen notification
  672. ;; method by assigning `notify-method' to one of 'notify-via-dbus
  673. ;; 'notify-via-libnotify or 'notify-via-message
  674. ;;; Code:
  675. (defvar notify-defaults (list :app "Emacs" :icon "emacs" :timeout 5000
  676. :urgency "low"
  677. :category "emacs.message")
  678. "Notification settings' defaults.
  679. May be overridden with key-value additional arguments to `notify'.")
  680. (defvar notify-delay '(0 5 0)
  681. "Minimum time allowed between notifications in time format.")
  682. (defvar notify-last-notification '(0 0 0) "Time of last notification.")
  683. (defvar notify-method 'notify-via-growl "Notification method among
  684. 'notify-via-dbus, 'notify-via-libnotify, 'notify-via-message or
  685. 'notify-via-growl")
  686. ;; determine notification method unless already set
  687. ;; prefer growl > D-Bus > libnotify > message
  688. (cond
  689. ((null notify-method)
  690. (setq notify-method
  691. (cond
  692. ((executable-find "growlnotify") 'notify-via-growl)
  693. ((and (require 'dbus nil t)
  694. (dbus-ping :session "org.freedesktop.Notifications"))
  695. (defvar notify-id 0 "Current D-Bus notification id.")
  696. 'notify-via-dbus)
  697. ((executable-find "notify-send") 'notify-via-libnotify)
  698. (t 'notify-via-message))))
  699. ((eq notify-method 'notify-via-dbus) ;housekeeping for pre-chosen DBus
  700. (if (and (require 'dbus nil t)
  701. (dbus-ping :session "org.freedesktop.Notifications"))
  702. (defvar notify-id 0 "Current D-Bus notification id.")
  703. (setq notify-method (if (executable-find "notify-send")
  704. 'notify-via-libnotify
  705. 'notify-via-message))))
  706. ((and (eq notify-method 'notify-via-libnotify)
  707. (not (executable-find "notify-send"))) ;housekeeping for pre-chosen libnotify
  708. (setq notify-method
  709. (if (and (require 'dbus nil t)
  710. (dbus-ping :session "org.freedesktop.Notifications"))
  711. (progn
  712. (defvar notify-id 0 "Current D-Bus notification id.")
  713. 'notify-via-dbus)
  714. 'notify-via-message)))
  715. ((and (eq notify-method 'notify-via-growl)
  716. (not (executable-find "growlnotify")))
  717. (setq notify-method 'notify-via-message)))
  718. (defun notify-via-dbus (title body)
  719. "Send notification with TITLE, BODY `D-Bus'."
  720. (dbus-call-method :session "org.freedesktop.Notifications"
  721. "/org/freedesktop/Notifications"
  722. "org.freedesktop.Notifications" "Notify"
  723. (get 'notify-defaults :app)
  724. (setq notify-id (+ notify-id 1))
  725. (get 'notify-defaults :icon) title body '(:array)
  726. '(:array :signature "{sv}") ':int32
  727. (get 'notify-defaults :timeout)))
  728. (defun notify-via-libnotify (title body)
  729. "Notify with TITLE, BODY via `libnotify'."
  730. (call-process "notify-send" nil 0 nil
  731. title body "-t"
  732. (number-to-string (get 'notify-defaults :timeout))
  733. "-i" (get 'notify-defaults :icon)
  734. "-u" (get 'notify-defaults :urgency)
  735. "-c" (get 'notify-defaults :category)))
  736. (defun notify-via-message (title body)
  737. "Notify TITLE, BODY with a simple message."
  738. (message "%s: %s" title body))
  739. (defun notify-via-growl (title body)
  740. "Notify TITLE, BODY with a growl"
  741. (call-process "growlnotify" nil 0 nil
  742. "-a" (get 'notify-defaults :app)
  743. "-n" (get 'notify-defaults :category)
  744. "-t" (notify-via-growl-stringify title)
  745. "-m" (notify-via-growl-stringify body)))
  746. (defun notify-via-growl-stringify (thing)
  747. (cond ((null thing) "")
  748. ((stringp thing) thing)
  749. (t (format "%s" thing))))
  750. (defun keywords-to-properties (symbol args &optional defaults)
  751. "Add to SYMBOL's property list key-values from ARGS and DEFAULTS."
  752. (when (consp defaults)
  753. (keywords-to-properties symbol defaults))
  754. (while args
  755. (put symbol (car args) (cadr args))
  756. (setq args (cddr args))))
  757. ;;;###autoload
  758. (defun notify (title body &rest args)
  759. "Notify TITLE, BODY via `notify-method'.
  760. ARGS may be amongst :timeout, :icon, :urgency, :app and :category."
  761. (when (time-less-p notify-delay
  762. (time-since notify-last-notification))
  763. (or (eq notify-method 'notify-via-message)
  764. (keywords-to-properties 'notify-defaults args
  765. notify-defaults))
  766. (setq notify-last-notification (current-time))
  767. (funcall notify-method title body)))
  768. (provide 'notify)
  769. ;;; notify.el ends here
  770. (require 'jabber)
  771. (setq jabber-history-enabled t
  772. jabber-use-global-history nil
  773. jabber-backlog-number 40
  774. jabber-backlog-days 30
  775. jabber-alert-presence-message-function (lambda (_who _oldstatus _newstatus _statustext) nil)
  776. )
  777. (setq jabber-account-list '(
  778. ("olson.levi@gmail.com"
  779. (:network-server . "talk.google.com")
  780. (:connection-type . ssl))
  781. ;; ("lolson@vlocity.com"
  782. ;; (:network-server . "talk.google.com")
  783. ;; (:connection-type . ssl))
  784. ))
  785. (defvar my-chat-prompt "[%t] %n>\n" "Customized chat prompt")
  786. (when (featurep 'jabber)
  787. (setq
  788. jabber-chat-foreign-prompt-format my-chat-prompt
  789. jabber-chat-local-prompt-format my-chat-prompt
  790. jabber-groupchat-prompt-format my-chat-prompt
  791. jabber-muc-private-foreign-prompt-format "[%t] %g/%n>\n"
  792. )
  793. )
  794. (defun notify-jabber-notify (from buf text _proposed-alert)
  795. "(jabber.el hook) Notify of new Jabber chat messages via notify.el"
  796. (when (or jabber-message-alert-same-buffer
  797. (not (memq (selected-window) (get-buffer-window-list buf))))
  798. (if (jabber-muc-sender-p from)
  799. (notify (format "(PM) %s"
  800. (jabber-jid-displayname (jabber-jid-user from)))
  801. (format "%s: %s" (jabber-jid-resource from) text)))
  802. (notify (format "%s" (jabber-jid-displayname from))
  803. text)))
  804. ;; (add-hook 'jabber-alert-message-hooks 'notify-jabber-notify)
  805. ;; (require 'autosmiley)
  806. ;; (add-hook 'jabber-chat-mode-hook 'autosmiley-mode)
  807. (defun jabber ()
  808. (interactive)
  809. (jabber-connect-all)
  810. (switch-to-buffer "*-jabber-roster-*"))
  811. (defun hyperspace-action->mu4e (&optional query)
  812. "Search mu4e with QUERY.
  813. If QUERY is unspecified, use the first bookmark in variable
  814. mu4e-bookmarks and update mail and index."
  815. (mu4e-headers-search (or query (caar mu4e-bookmarks)))
  816. (unless query
  817. (mu4e-update-mail-and-index nil)))
  818. (add-to-list 'hyperspace-actions '("m4" . hyperspace-action->mu4e))
  819. (defun hyperspace-action->elfeed (&optional query)
  820. "Load elfeed, optionally searching for QUERY."
  821. (elfeed)
  822. (if query
  823. (elfeed-search-set-filter query)
  824. (elfeed-search-fetch nil)))
  825. (add-to-list 'hyperspace-actions '("lf" . hyperspace-action->elfeed))
  826. (require 'rainbow-delimiters)
  827. (global-flycheck-mode)
  828. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  829. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  830. (setq-default indent-tabs-mode nil
  831. tab-width 4)
  832. (defvaralias 'c-basic-offset 'tab-width)
  833. (defvaralias 'cperl-indent-level 'tab-width)
  834. (electric-pair-mode 1)
  835. (show-paren-mode 1)
  836. (require 'dockerfile-mode)
  837. (add-to-list 'auto-mode-alist '("Dockerfile*\\'" . dockerfile-mode))
  838. (require 'gitignore-mode)
  839. (add-to-list 'auto-mode-alist '("gitignore\\'" . gitignore-mode))
  840. (require 'json-mode)
  841. (add-to-list 'auto-mode-alist '("\\.json\\'" . json-mode))
  842. (require 'web-mode)
  843. (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
  844. (elpy-enable)
  845. (setq python-shell-interpreter "jupyter"
  846. python-shell-interpreter-args "console --simple-prompt")
  847. (when (require 'flycheck nil t)
  848. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  849. (add-hook 'elpy-mode-hook 'flycheck-mode))
  850. (require 'py-autopep8)
  851. (setq py-autopep8-options '("--ignore=E501"))
  852. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
  853. (require 'go-mode)
  854. (require 'go-playground)
  855. (require 'gorepl-mode)
  856. (require 'company-go)
  857. (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))
  858. (add-hook 'go-mode-hook (lambda ()
  859. (add-hook 'before-save-hook 'gofmt-before-save)
  860. (local-set-key (kbd "M-.") 'godef-jump)
  861. (local-set-key (kbd "M-,") 'pop-tag-mark)
  862. (local-set-key (kbd "C-c C-c") (lambda ()
  863. (interactive)
  864. (ansi-term)
  865. (comint-send-string "*ansi-term*" "make\n")))
  866. (set (make-local-variable 'company-backends) '(company-go))
  867. (setq company-tooltip-limit 20
  868. company-echo-delay 0
  869. company-begin-commands '(self-insert-command))
  870. (gorepl-mode)))
  871. (defun set-exec-path-from-shell-PATH ()
  872. (let ((path-from-shell (replace-regexp-in-string
  873. "[ \t\n]*$"
  874. ""
  875. (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
  876. (setenv "PATH" path-from-shell)
  877. (setq eshell-path-env path-from-shell)
  878. (setq exec-path (split-string path-from-shell path-separator))))
  879. (when window-system (set-exec-path-from-shell-PATH))
  880. (setenv "GOPATH" "~/go")
  881. (add-to-list 'exec-path "~/go/bin")
  882. (defun setup-tide-mode ()
  883. "Tide setup function."
  884. (interactive)
  885. (tide-setup)
  886. (flycheck-mode +1)
  887. (setq flycheck-check-syntax-automatically '(save mode-enabled))
  888. (eldoc-mode +1)
  889. (tide-hl-identifier-mode +1)
  890. (company-mode +1))
  891. ;; aligns annotation to the right hand side
  892. (setq company-tooltip-align-annotations t)
  893. ;; formats the buffer before saving
  894. (add-hook 'before-save-hook 'tide-format-before-save)
  895. (add-hook 'typescript-mode-hook #'setup-tide-mode)
  896. (require 'typescript-mode)
  897. (require 'tide)
  898. (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
  899. (add-hook 'typescript-mode-hook
  900. '(lambda ()
  901. (set (make-local-variable 'company-backends) '(company-tide))
  902. (setq company-tooltip-limit 20
  903. company-echo-delay 0
  904. company-begin-commands '(self-insert-command)
  905. tide-format-options '(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t :placeOpenBraceOnNewLineForFunctions nil))
  906. (tide-setup)))
  907. (require 'web-mode)
  908. (add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
  909. (add-hook 'web-mode-hook
  910. (lambda ()
  911. (when (string-equal "tsx" (file-name-extension buffer-file-name))
  912. (setup-tide-mode))))
  913. ;; enable typescript-tslint checker
  914. (flycheck-add-mode 'typescript-tslint 'web-mode)
  915. (require 'web-mode)
  916. (add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
  917. (add-hook 'web-mode-hook
  918. (lambda ()
  919. (when (string-equal "jsx" (file-name-extension buffer-file-name))
  920. (setup-tide-mode))))
  921. ;; configure jsx-tide checker to run after your default jsx checker
  922. (flycheck-add-mode 'javascript-eslint 'web-mode)
  923. (flycheck-add-next-checker 'javascript-eslint 'jsx-tide 'append)
  924. (org-babel-do-load-languages
  925. 'org-babel-load-languages
  926. '((js . t)
  927. (shell . t)
  928. (emacs-lisp . t)))
  929. (setq org-todo-keywords
  930. '((sequence "TODO(t)" "|" "DONE(d)")
  931. (sequence "BUG(b)" "|" "INPROGRESS(i)" "FIXED(f)")
  932. (sequence "|" "CANCELED(c)")
  933. (sequence "|" "NEEDCLARIFICATION(n)")
  934. (sequence "|" "PROVIDEUPDATE(p)")
  935. (sequence "|" "WAITING(w)")
  936. ))
  937. (setq org-agenda-files
  938. '("~/Dropbox/Org/todo.org" "~/Dropbox/Org/archive.org"))
  939. (setq org-refile-targets
  940. '((nil :maxlevel . 1)
  941. (org-agenda-files :maxlevel . 1)))
  942. (add-hook 'focus-in-hook
  943. (lambda () (progn
  944. (setq org-tags-column (- 5 (frame-width)))) (org-align-all-tags)))
  945. (add-hook 'focus-out-hook
  946. (lambda () (progn
  947. (setq org-tags-column (- 5 (frame-width)))) (org-align-all-tags)))
  948. (defvar org-src-tab-acts-natively)
  949. (setq org-src-tab-acts-natively t)
  950. ;; (setenv "NODE_PATH"
  951. ;; (getenv "NODE_PATH"))
  952. (defvar org-confirm-babel-evaluate)
  953. (defun my-org-confirm-babel-evaluate (lang _body)
  954. "Execute certain languages without confirming.
  955. Takes LANG to allow and BODY to execute."
  956. (not (or (string= lang "js")
  957. (string= lang "restclient")
  958. (string= lang "emacs-lisp")
  959. (string= lang "shell"))))
  960. (setq org-confirm-babel-evaluate #'my-org-confirm-babel-evaluate)
  961. (add-to-list 'org-structure-template-alist
  962. (list "e" (concat "#+BEGIN_SRC emacs-lisp :results silent\n"
  963. "\n"
  964. "#+END_SRC")))
  965. (add-to-list 'org-structure-template-alist
  966. (list "j" (concat "#+BEGIN_SRC js :cmd \"babel-node\"\n"
  967. "\n"
  968. "#+END_SRC")))
  969. (add-to-list 'org-structure-template-alist
  970. (list "r" (concat "#+BEGIN_SRC restclient :results raw\n"
  971. "\n"
  972. "#+END_SRC")))
  973. ;;store org-mode links to messages
  974. (require 'org-mu4e)
  975. ;;store link to message if in header view, not to header query
  976. (setq org-mu4e-link-query-in-headers-mode nil)
  977. (setq org-capture-templates
  978. '(("t" "todo" entry (file+headline "~/Dropbox/Org/todo.org" "Tasks")
  979. "* TODO [#A] %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n%a\n")))
  980. (elfeed-org)
  981. (setq rmh-elfeed-org-files (list "~/Dropbox/Org/elfeed.org"))
  982. (defun leo/elfeed-search (arg)
  983. "Search for ARG in feed."
  984. (interactive)
  985. (elfeed-search-set-filter arg))
  986. (define-key elfeed-search-mode-map "a" (lambda () (interactive) (leo/elfeed-search "")))
  987. (define-key elfeed-search-mode-map "e" (lambda () (interactive) (leo/elfeed-search "+emacs")))
  988. (define-key elfeed-search-mode-map "d" (lambda () (interactive) (leo/elfeed-search "+daily")))
  989. (define-key elfeed-search-mode-map "x" (lambda () (interactive) (leo/elfeed-search "xkcd")))
  990. (defun find-user-init-file ()
  991. "Edit the `~/.emacs.d/init.org' file."
  992. (interactive)
  993. (find-file "~/.emacs.d/init.org"))
  994. (defun find-todo-file ()
  995. "Edit the `~/todo.org' file."
  996. (interactive)
  997. (find-file "~/Dropbox/Org/todo.org"))
  998. (defun load-user-init-file ()
  999. "LO: Reload the `~/.emacs.d/init.elc' file."
  1000. (interactive)
  1001. (load-file "~/.emacs.d/init.elc"))
  1002. (defun jump-to-symbol-internal (&optional backwardp)
  1003. "Jumps to the next symbol near the point if such a symbol exists. If BACKWARDP is non-nil it jumps backward."
  1004. (let* ((point (point))
  1005. (bounds (find-tag-default-bounds))
  1006. (beg (car bounds)) (end (cdr bounds))
  1007. (str (isearch-symbol-regexp (find-tag-default)))
  1008. (search (if backwardp 'search-backward-regexp
  1009. 'search-forward-regexp)))
  1010. (goto-char (if backwardp beg end))
  1011. (funcall search str nil t)
  1012. (cond ((<= beg (point) end) (goto-char point))
  1013. (backwardp (forward-char (- point beg)))
  1014. (t (backward-char (- end point))))))
  1015. (defun jump-to-previous-like-this ()
  1016. "Jumps to the previous occurrence of the symbol at point."
  1017. (interactive)
  1018. (jump-to-symbol-internal t))
  1019. (defun jump-to-next-like-this ()
  1020. "Jumps to the next occurrence of the symbol at point."
  1021. (interactive)
  1022. (jump-to-symbol-internal))
  1023. (defun match-paren (arg)
  1024. "Go to the matching paren if on a paren; otherwise insert ARG (a literal % sign)."
  1025. (interactive "p")
  1026. (cond ((looking-at "\\s(") (forward-list 1))
  1027. ((looking-back "\\s(" 2) (backward-char 1) (forward-list 1))
  1028. ((looking-at "\\s)") (forward-char 1) (backward-list 1))
  1029. ((looking-back "\\s)" 2) (backward-list 1))
  1030. (t (self-insert-command (or arg 1)))))
  1031. (defun kill-this-buffer-unless-scratch ()
  1032. "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."
  1033. (interactive)
  1034. (if (not (string= (buffer-name) "*scratch*"))
  1035. (kill-this-buffer)
  1036. (delete-region (point-min) (point-max))
  1037. (switch-to-buffer (other-buffer))
  1038. (bury-buffer "*scratch*")))
  1039. (defun delete-backward-sentence ()
  1040. "LO: Delete to the beginning of the sentence/line."
  1041. (interactive)
  1042. (delete-region (point) (progn (backward-sentence) (point))))
  1043. (defun delete-backward-to-boundary (arg)
  1044. "LO: Delete backward to the previous word boundary. With ARG, do this many times."
  1045. (interactive "p")
  1046. (let ((a (point))
  1047. (b (progn
  1048. (backward-word arg)
  1049. (forward-word)
  1050. (point))))
  1051. (if (< a b)
  1052. (delete-region a (progn (backward-word arg) (point)))
  1053. (if (= a b)
  1054. (delete-region a (progn (backward-word arg) (point)))
  1055. (delete-region a b)))))
  1056. (defun comment-or-uncomment-region-or-line ()
  1057. "Comments or uncomments the region or the current line if there's no active region."
  1058. (interactive)
  1059. (let (beg end)
  1060. (if (region-active-p)
  1061. (setq beg (region-beginning) end (region-end))
  1062. (setq beg (line-beginning-position) end (line-end-position)))
  1063. (comment-or-uncomment-region beg end)))
  1064. (defun fold-toggle (column)
  1065. "Code folding by COLUMN."
  1066. (interactive "P")
  1067. (set-selective-display
  1068. (or column
  1069. (unless selective-display
  1070. (1+ (current-column))))))
  1071. (defun new-line-below ()
  1072. "LO: Create a new line below current line."
  1073. (interactive)
  1074. (move-end-of-line 1)
  1075. (newline-and-indent))
  1076. (defun new-line-above ()
  1077. "LO: Create a new line above current line."
  1078. (interactive)
  1079. (move-beginning-of-line 1)
  1080. (newline)
  1081. (forward-line -1))
  1082. (defun duplicate-thing (comment)
  1083. "LO: Duplicates the current line, or the region if active. If an argument (COMMENT) is given, the duplicated region will be commented out."
  1084. (interactive "P")
  1085. (save-excursion
  1086. (let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
  1087. (end (if (region-active-p) (region-end) (point-at-eol))))
  1088. (goto-char end)
  1089. (unless (region-active-p)
  1090. (newline))
  1091. (insert (buffer-substring start end))
  1092. (when comment (comment-region start end)))))
  1093. (defun tidy ()
  1094. "LO: Ident, untabify and unwhitespacify current buffer, or region if active."
  1095. (interactive)
  1096. (let ((beg (if (region-active-p) (region-beginning) (point-min)))
  1097. (end (if (region-active-p) (region-end) (point-max))))
  1098. (let ((inhibit-message t))
  1099. (indent-region beg end))
  1100. (whitespace-cleanup)
  1101. (untabify beg (if (< end (point-max)) end (point-max)))
  1102. (if (region-active-p) (message "Indenting Region...Done") (message "Indenting File...Done"))))
  1103. (defun phil-columns ()
  1104. "LO: Good 'ol Phil-Columns."
  1105. (interactive)
  1106. (message "Good 'ol fill-columns")
  1107. (with-output-to-temp-buffer "*PHIL-COLUMN*"
  1108. (shell-command "mpv --no-video 'https://www.youtube.com/watch?v=YkADj0TPrJA&t=3m16s' > /dev/null 2>&1 & sleep 8; pkill mpv"))
  1109. (other-window 1)
  1110. (delete-window))
  1111. (declare-function first "Goto FIRST shell.")
  1112. (declare-function goto-non-shell-buffer "Goto something other than a shell buffer.")
  1113. (declare-function switch-shell "Switch shell.")
  1114. (let ((last-shell ""))
  1115. (defun toggle-shell ()
  1116. (interactive)
  1117. (cond ((string-match-p "^\\*shell<[1-9][0-9]*>\\*$" (buffer-name))
  1118. (goto-non-shell-buffer))
  1119. ((get-buffer last-shell) (switch-to-buffer last-shell))
  1120. (t (shell (setq last-shell "*shell<1>*")))))
  1121. (defun switch-shell (n)
  1122. (let ((buffer-name (format "*shell<%d>*" n)))
  1123. (setq last-shell buffer-name)
  1124. (cond ((get-buffer buffer-name)
  1125. (switch-to-buffer buffer-name))
  1126. (t (shell buffer-name)
  1127. (rename-buffer buffer-name)))))
  1128. (defun goto-non-shell-buffer ()
  1129. (let* ((r "^\\*shell<[1-9][0-9]*>\\*$")
  1130. (shell-buffer-p (lambda (b) (string-match-p r (buffer-name b))))
  1131. (non-shells (cl-remove-if shell-buffer-p (buffer-list))))
  1132. (when non-shells
  1133. (switch-to-buffer (first non-shells))))))
  1134. (defadvice shell (after kill-with-no-query nil activate)
  1135. "."
  1136. (set-process-query-on-exit-flag (get-buffer-process ad-return-value) nil))
  1137. (declare-function comint-truncate-buffer ".")
  1138. (defun clear-comint ()
  1139. "Run `comint-truncate-buffer' with the `comint-buffer-maximum-size' set to zero."
  1140. (interactive)
  1141. (let ((comint-buffer-maximum-size 0))
  1142. (comint-truncate-buffer)))
  1143. (defun c-setup ()
  1144. "Compile."
  1145. (local-set-key (kbd "C-c C-c") 'compile))
  1146. (require 'company)
  1147. (add-hook 'comint-mode-hook (lambda () (local-set-key (kbd "c-l") 'clear-comint)))
  1148. (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
  1149. (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
  1150. (add-hook 'c-mode-common-hook 'c-setup)
  1151. (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
  1152. (defvar company-active-map (make-keymap)
  1153. "company mode keymap.")
  1154. (defvar custom-bindings (make-keymap)
  1155. "a keymap of custom bindings.")
  1156. (define-key custom-bindings (kbd "M-p") 'jump-to-previous-like-this)
  1157. (define-key custom-bindings (kbd "M-n") 'jump-to-next-like-this)
  1158. (define-key custom-bindings (kbd "M-<tab>") 'switch-to-next-buffer)
  1159. (define-key custom-bindings (kbd "M-<backspace>")'delete-backward-to-boundary)
  1160. (define-key custom-bindings (kbd "C-<backspace>")'delete-backward-to-boundary)
  1161. (define-key custom-bindings (kbd "C-}") 'mc/mark-next-like-this)
  1162. (define-key custom-bindings (kbd "C-)") 'mc/unmark-next-like-this)
  1163. (define-key custom-bindings (kbd "C-{") 'mc/mark-previous-like-this)
  1164. (define-key custom-bindings (kbd "C-(") 'mc/unmark-previous-like-this)
  1165. (define-key custom-bindings (kbd "C-'") 'mc-hide-unmatched-lines-mode)
  1166. (define-key custom-bindings (kbd "C-c 1") 'mc/insert-numbers)
  1167. (define-key custom-bindings (kbd "C-c s") 'mc/sort-regions)
  1168. (define-key custom-bindings "%" 'match-paren)
  1169. (define-key custom-bindings (kbd "C-x .") 'dash-at-point)
  1170. (define-key custom-bindings (kbd "C-x ,") 'dash-at-point-with-docset)
  1171. (define-key custom-bindings (kbd "C-s") (lambda () (interactive) (swiper (format "%s" (thing-at-point 'symbol)))))
  1172. (define-key custom-bindings (kbd "C-x C-l m") 'mu4e)
  1173. (define-key custom-bindings (kbd "C-x C-o t") 'find-todo-file)
  1174. (define-key custom-bindings (kbd "C-x C-l j") 'jabber)
  1175. (define-key custom-bindings (kbd "C-x C-l f") 'elfeed)
  1176. (define-key custom-bindings (kbd "C-x C-l a") 'org-agenda)
  1177. (define-key custom-bindings (kbd "C-x C-l c") 'calendar)
  1178. (define-key custom-bindings (kbd "M-SPC") #'hyperspace)
  1179. ;; (dolist (n (number-sequence 1 9))
  1180. ;; (global-set-key (kbd (concat "M-" (int-to-string n)))
  1181. ;; (lambda () (interactive) (switch-shell n))))
  1182. (define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)
  1183. (define-key company-active-map (kbd "C-n") 'company-select-next)
  1184. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  1185. (define-key company-active-map (kbd "<tab>") 'company-complete)
  1186. (define-key custom-bindings (kbd "C-c p") 'counsel-projectile-switch-project)
  1187. (define-key custom-bindings (kbd "C-c f") 'counsel-projectile-find-file)
  1188. (define-key custom-bindings (kbd "C-c m") 'magit-status)
  1189. (define-key custom-bindings (kbd "C-c D") 'define-word-at-point)
  1190. (define-key custom-bindings (kbd "C-@") 'er/expand-region)
  1191. (define-key custom-bindings (kbd "C-#") 'er/contract-region)
  1192. (define-key custom-bindings (kbd "C-S-c C-S-c") 'mc/edit-lines)
  1193. (define-key custom-bindings (kbd "C-c b") 'ivy-switch-buffer)
  1194. (define-key custom-bindings (kbd "C-c l") 'org-store-link)
  1195. (define-key custom-bindings (kbd "C-c t") 'org-set-tags)
  1196. (define-key custom-bindings (kbd "M-u") 'upcase-dwim)
  1197. (define-key custom-bindings (kbd "M-c") 'capitalize-dwim)
  1198. (define-key custom-bindings (kbd "M-l") 'downcase-dwim)
  1199. (define-key custom-bindings (kbd "M-o") 'other-window)
  1200. (define-key custom-bindings (kbd "C-c s") 'ispell-word)
  1201. (define-key custom-bindings (kbd "C-c C-d") 'org-capture)
  1202. (define-key custom-bindings (kbd "C-c <up>") 'windmove-up)
  1203. (define-key custom-bindings (kbd "C-c <down>") 'windmove-down)
  1204. (define-key custom-bindings (kbd "C-c <left>") 'windmove-left)
  1205. (define-key custom-bindings (kbd "C-c <right>") 'windmove-right)
  1206. (define-key custom-bindings (kbd "C-c a") (lambda () (interactive) (org-agenda nil "n")))
  1207. (define-key custom-bindings (kbd "C-c e") 'find-user-init-file)
  1208. (define-key custom-bindings (kbd "C-x f") 'phil-columns)
  1209. (define-key custom-bindings (kbd "C-x k") 'kill-this-buffer-unless-scratch)
  1210. (define-key custom-bindings (kbd "C-c d") 'duplicate-thing)
  1211. (define-key custom-bindings (kbd "C-c c") 'comment-or-uncomment-region-or-line)
  1212. (define-key custom-bindings (kbd "C-;") 'comment-or-uncomment-region-or-line)
  1213. (define-key custom-bindings (kbd "C-o") 'new-line-below)
  1214. (define-key custom-bindings (kbd "C-S-o") 'new-line-above)
  1215. (define-key custom-bindings (kbd "<C-tab>") 'tidy)
  1216. (define-key custom-bindings (kbd "M-q") 'kill-this-buffer)
  1217. (define-key custom-bindings (kbd "M-RET") '(lambda () (interactive) (term (getenv "SHELL"))))
  1218. (define-minor-mode custom-bindings-mode
  1219. "A mode that activates custom-bindings."
  1220. t nil custom-bindings)
  1221. (cond ((member "PragmataPro Mono Liga" (font-family-list))
  1222. (set-face-attribute 'default nil :font "PragmataPro Mono Liga-13")))
  1223. (require 'doom-modeline)
  1224. (doom-modeline-mode 1)
  1225. ;; How tall the mode-line should be (only respected in GUI Emacs).
  1226. (setq doom-modeline-height 30)
  1227. ;; How wide the mode-line bar should be (only respected in GUI Emacs).
  1228. (setq doom-modeline-bar-width 4)
  1229. ;; Determines the style used by `doom-modeline-buffer-file-name'.
  1230. ;;
  1231. ;; Given ~/Projects/FOSS/emacs/lisp/comint.el
  1232. ;; truncate-upto-project => ~/P/F/emacs/lisp/comint.el
  1233. ;; truncate-from-project => ~/Projects/FOSS/emacs/l/comint.el
  1234. ;; truncate-with-project => emacs/l/comint.el
  1235. ;; truncate-except-project => ~/P/F/emacs/l/comint.el
  1236. ;; truncate-upto-root => ~/P/F/e/lisp/comint.el
  1237. ;; truncate-all => ~/P/F/e/l/comint.el
  1238. ;; relative-from-project => emacs/lisp/comint.el
  1239. ;; relative-to-project => lisp/comint.el
  1240. ;; file-name => comint.el
  1241. ;; buffer-name => comint.el<2> (uniquify buffer name)
  1242. ;;
  1243. ;; If you are expereicing the laggy issue, especially while editing remote files
  1244. ;; with tramp, please try `file-name' style.
  1245. ;; Please refer to https://github.com/bbatsov/projectile/issues/657.
  1246. (setq doom-modeline-buffer-file-name-style 'truncate-upto-project)
  1247. ;; What executable of Python will be used (if nil nothing will be showed).
  1248. (setq doom-modeline-python-executable "python")
  1249. ;; Whether show `all-the-icons' or not (if nil nothing will be showed).
  1250. (setq doom-modeline-icon t)
  1251. ;; Whether show the icon for major mode. It respects `doom-modeline-icon'.
  1252. (setq doom-modeline-major-mode-icon t)
  1253. ;; Display color icons for `major-mode'. It respects `all-the-icons-color-icons'.
  1254. (setq doom-modeline-major-mode-color-icon nil)
  1255. ;; Whether display minor modes or not. Non-nil to display in mode-line.
  1256. (setq doom-modeline-minor-modes nil)
  1257. ;; If non-nil, a word count will be added to the selection-info modeline segment.
  1258. (setq doom-modeline-enable-word-count nil)
  1259. ;; If non-nil, only display one number for checker information if applicable.
  1260. (setq doom-modeline-checker-simple-format t)
  1261. ;; Whether display perspective name or not. Non-nil to display in mode-line.
  1262. (setq doom-modeline-persp-name t)
  1263. ;; Whether display `lsp' state or not. Non-nil to display in mode-line.
  1264. (setq doom-modeline-lsp t)
  1265. ;; Whether display github notifications or not. Requires `ghub` package.
  1266. (setq doom-modeline-github nil)
  1267. ;; The interval of checking github.
  1268. (setq doom-modeline-github-interval (* 30 60))
  1269. ;; Whether display environment version or not.
  1270. (setq doom-modeline-env-version t)
  1271. ;; Whether display mu4e notifications or not. Requires `mu4e-alert' package.
  1272. (setq doom-modeline-mu4e t)