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.

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