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.

1501 lines
57 KiB

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