Advertisement
jcarterwood

Emacs init.el

Jan 27th, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.95 KB | None | 0 0
  1.  
  2. ;; *** BASIC SET-UP ***
  3.  
  4. ;;
  5. ;; Open emacs in full-size window
  6. ;;
  7.  
  8.  
  9. (add-to-list 'default-frame-alist '(fullscreen . maximized))
  10.  
  11. ;;
  12. ;; Inhibit startscreen
  13. ;;
  14.  
  15. (setq inhibit-startup-screen t)
  16.  
  17. ;; Install package manager
  18.  
  19. (setq package-archives
  20. '(("gnu" . "http://elpa.gnu.org/packages/")
  21. ("melpa" . "http://melpa.org/packages/")))
  22. (package-initialize)
  23.  
  24. ;; Enable recent-file-mode
  25.  
  26. (recentf-mode 1)
  27. (setq recentf-max-menu-items 35)
  28. (setq recentf-max-saved-items 35)
  29. (global-set-key "\C-x\ \C-r" 'recentf-open-files)
  30.  
  31. ;; System locale to use for formatting time values.
  32. (setq system-time-locale "C") ; Make sure that the weekdays in the
  33. ; time stamps of your Org mode files and
  34. ; in the agenda appear in English.
  35.  
  36.  
  37. ;; Global visual line mode
  38. (global-visual-line-mode 1); proper line wrapping
  39.  
  40.  
  41. ;;
  42. ;; *** MARKDOWN ***
  43. ;;
  44.  
  45. ;;
  46. ;; Set visual-line-mode automatically for .md/Markdown files
  47. ;;
  48.  
  49. (add-hook 'markdown-mode-hook #'visual-line-mode)
  50.  
  51. ;;
  52. ;; Set up Flyspell for text mode (but not for change-log-mode and log-edit-mode
  53. ;; (Can add additional exceptions as necessary.)
  54. ;;
  55.  
  56. (dolist (hook '(text-mode-hook))
  57. (add-hook hook (lambda () (flyspell-mode 1))))
  58. (dolist (hook '(change-log-mode-hook log-edit-mode-hook))
  59. (add-hook hook (lambda () (flyspell-mode -1))))
  60.  
  61. (setq ispell-dictionary "en_GB-ise") ;set the default dictionary
  62.  
  63.  
  64.  
  65. ;;
  66. ;; Automatic flyspell-mode with markdown
  67. ;;
  68.  
  69. (add-hook 'markdown-mode-hook 'flyspell-mode)
  70.  
  71. ;;
  72. ;; Set new commands to switch between English and German dictionaries
  73. ;;
  74.  
  75.  
  76. (defun flyspell-german ()
  77. (interactive)
  78. (ispell-change-dictionary "de_DE")
  79. (flyspell-buffer))
  80.  
  81. (defun flyspell-english ()
  82. (interactive)
  83. (ispell-change-dictionary "default")
  84. (flyspell-buffer))
  85.  
  86.  
  87. ;;
  88. ;; Attach shortcuts to change-dictionary commands
  89. ;;
  90.  
  91. (global-set-key (kbd "<f5>") 'flyspell-english)
  92. (global-set-key (kbd "<f6>") 'flyspell-german)
  93.  
  94.  
  95. ;;
  96. ;; Auto-start gfm-mode with markdown.
  97. ;;
  98.  
  99. (add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode))
  100.  
  101.  
  102.  
  103. ;;
  104. ;; Add new face for citations (including entire citation text)
  105. ;;
  106.  
  107. (defface pandoc-citation-face
  108. '((t :foreground "dark orange"))
  109. "Face for pandoc citation syntax")
  110.  
  111. (font-lock-add-keywords
  112. 'gfm-mode
  113. '(("\\B\\[[^][]*@[[:alnum:]_]+[^][]*\\]" . 'pandoc-citation-face)))
  114.  
  115.  
  116. ;;
  117. ;; ALTERNATIVE: Add new face for markdown mode: citations only
  118. ;;
  119.  
  120. ;;(defface pandoc-citation-face
  121. ;; '((t :foreground "dark orange"))
  122. ;; "Face for pandoc citation syntax")
  123.  
  124. ;;(font-lock-add-keywords
  125. ;; 'gfm-mode
  126. ;; '(("\\B\\(-?@[[:alnum:]_][-_[:alnum:]:.#$%&+?<>~/]+\\)" . 'pandoc-citation-face)))
  127.  
  128.  
  129. ;;
  130. ;; Auto insert text in new markdown files
  131. ;; See: http://www.howardism.org/Technical/Emacs/templates-tutorial.html
  132. ;;
  133.  
  134. (use-package autoinsert
  135. :init
  136. ;; Don't want to be prompted before insertion:
  137. (setq auto-insert-query nil)
  138.  
  139. (setq auto-insert-directory (locate-user-emacs-file "templates"))
  140. (add-hook 'find-file-hook 'auto-insert)
  141. (auto-insert-mode 1)
  142.  
  143. :config
  144. (define-auto-insert "\\.md?$" "default-md.md"))
  145.  
  146. ;;
  147. ;; Set asymmetric headings (# Heading instead of # Heading #)
  148. ;;
  149.  
  150. (setq markdown-asymmetric-header t)
  151.  
  152. ;;
  153. ;; Insert [@ ] ready for input with keystroke
  154. ;;
  155.  
  156. (defun ref-insert ()
  157. (interactive)
  158. (insert "[@]")
  159. (backward-char)
  160. )
  161. (global-set-key (kbd "C-c r") 'ref-insert)
  162.  
  163.  
  164. ;;
  165. ;; HAVE DISABLED YASNIPPET BECAUSE IT INTERFERES WITH ORG-MODE KEY BINDINGS
  166. ;;
  167. ;; set-up yasnippet
  168. ;; See: http://www.howardism.org/Technical/Emacs/templates-tutorial.html
  169. ;;
  170.  
  171. ;; (use-package yasnippet
  172. ;; :ensure t
  173. ;; :init
  174. ;; (yas-global-mode 1)
  175. ;; :config
  176. ;; (add-to-list 'yas-snippet-dirs (locate-user-emacs-file "snippets")))
  177.  
  178. ;;
  179. ;; Set up automatic word-count (via Sacha Chua: https://sachachua.com/blog/2008/01/outlining-your-notes-with-org/
  180. ;;
  181.  
  182. (defvar count-words-buffer
  183. nil
  184. "*Number of words in the buffer.")
  185.  
  186. (defun wicked/update-wc ()
  187. (interactive)
  188. (setq count-words-buffer (number-to-string (count-words-buffer)))
  189. (force-mode-line-update))
  190.  
  191. ; only setup timer once
  192. (unless count-words-buffer
  193. ;; seed count-words-paragraph
  194. ;; create timer to keep count-words-paragraph updated
  195. (run-with-idle-timer 1 t 'wicked/update-wc))
  196.  
  197. ;; add count words paragraph the mode line
  198. (unless (memq 'count-words-buffer global-mode-string)
  199. (add-to-list 'global-mode-string "words: " t)
  200. (add-to-list 'global-mode-string 'count-words-buffer t))
  201.  
  202. ;; count number of words in current paragraph
  203. (defun count-words-buffer ()
  204. "Count the number of words in the current paragraph."
  205. (interactive)
  206. (save-excursion
  207. (goto-char (point-min))
  208. (let ((count 0))
  209. (while (not (eobp))
  210. (forward-word 1)
  211. (setq count (1+ count)))
  212. count)))
  213.  
  214.  
  215.  
  216. ;;
  217. ;; Enable SHIFT-Tab to move text four spaces to the left
  218. ;;
  219.  
  220. (global-set-key (kbd "<backtab>") 'un-indent-by-removing-4-spaces)
  221. (defun un-indent-by-removing-4-spaces ()
  222. "remove 4 spaces from beginning of of line"
  223. (interactive)
  224. (save-excursion
  225. (save-match-data
  226. (beginning-of-line)
  227. ;; get rid of tabs at beginning of line
  228. (when (looking-at "^\\s-+")
  229. (untabify (match-beginning 0) (match-end 0)))
  230. (when (looking-at "^ ")
  231. (replace-match "")))))
  232.  
  233.  
  234.  
  235.  
  236. ;;
  237. ;; Enable easier window resizing with ALT+arrow keys
  238. ;;
  239.  
  240. (global-set-key (kbd "<M-up>") 'shrink-window)
  241. (global-set-key (kbd "<M-down>") 'enlarge-window)
  242. (global-set-key (kbd "<M-left>") 'shrink-window-horizontally)
  243. (global-set-key (kbd "<M-right>")'enlarge-window-horizontally)
  244.  
  245. ;;
  246. ;; Set apropos to sort search results by relevancy
  247. ;;
  248.  
  249. (setq apropos-sort-by-scores t)
  250.  
  251. ;;
  252. ;; Add euro symbol that can be displayed with M-x euro
  253. ;;
  254.  
  255. (fset 'euro
  256. (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([24 56 return 35 120 50 48 65 67 return] 0 "%d")) arg)))
  257.  
  258. ;;
  259. ;; Bind M-o to change windows (C-x o)
  260. ;;
  261.  
  262. (global-set-key (kbd "M-o") 'other-window)
  263.  
  264.  
  265. ;;
  266. ;; Set IDO mode for file and directory finding
  267. ;;
  268.  
  269. (ido-mode 1)
  270. (setq ido-everywhere t)
  271. (setq ido-enable-flex-matching t)
  272.  
  273. ;;Add Neotree (toggle with F7) ;; Not currently using Neotree, using regular IDO-mode instead
  274. ;;
  275. ;; (add-to-list 'load-path "/home/john/.emacs.d/neotree")
  276. ;; (require 'neotree)
  277. ;; (global-set-key [f7] 'neotree-toggle)
  278.  
  279.  
  280. (custom-set-variables
  281. ;; custom-set-variables was added by Custom.
  282. ;; If you edit it by hand, you could mess it up, so be careful.
  283. ;; Your init file should contain only one such instance.
  284. ;; If there is more than one, they won't work right.
  285. '(ansi-color-faces-vector
  286. [default default default italic underline success warning error])
  287. '(ansi-color-names-vector
  288. ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
  289. '(custom-enabled-themes '(wheatgrass))
  290. '(ido-mode 'buffer nil (ido))
  291. '(org-agenda-files '("~/Documents/org/todo.org"))
  292. '(org-archive-subtree-add-inherited-tags t)
  293. '(org-export-backends '(ascii beamer html icalendar latex md odt))
  294. '(package-selected-packages
  295. '(helm-bibtex helm-org use-package lorem-ipsum auctex-latexmk auctex impatient-mode skewer-mode markdown-mode)))
  296. (custom-set-faces
  297. ;; custom-set-faces was added by Custom.
  298. ;; If you edit it by hand, you could mess it up, so be careful.
  299. ;; Your init file should contain only one such instance.
  300. ;; If there is more than one, they won't work right.
  301. '(markdown-blockquote-face ((t (:inherit font-lock-doc-face :foreground "dark orange"))))
  302. '(markdown-bold-face ((t (:inherit bold :foreground "gold"))))
  303. '(markdown-italic-face ((t (:inherit italic :foreground "magenta")))))
  304.  
  305. ;;
  306. ;; helm-bibtex
  307. ;;
  308.  
  309. (require 'helm)
  310.  
  311. ;;
  312. ;; helm-bibtex set up location of Bibtex bibliographies
  313. ;;
  314.  
  315. (setq bibtex-completion-bibliography
  316. '("/home/john/Documents/libraries/Religion.bib"
  317. "/home/john/Documents/libraries/Crime_and_violence.bib"))
  318.  
  319.  
  320. ;; helm-bibtex: keybindings (ORIGINAL CODE)
  321.  
  322. (require 'helm-config)
  323.  
  324. (global-set-key (kbd "<menu>") 'helm-command-prefix)
  325.  
  326. (define-key helm-command-map "b" 'helm-bibtex)
  327. (define-key helm-command-map "B" 'helm-bibtex-with-local-bibliography)
  328. (define-key helm-command-map "n" 'helm-bibtex-with-notes)
  329. (define-key helm-command-map (kbd "<menu>") 'helm-resume)
  330.  
  331. (setq bibtex-completion-format-citation-functions
  332. '((org-mode . bibtex-completion-format-citation-org-link-to-PDF)
  333. (latex-mode . bibtex-completion-format-citation-cite)
  334. (markdown-mode . bibtex-completion-format-citation-pandoc-citeproc)
  335. (gfm-mode . bibtex-completion-format-citation-pandoc-citeproc)
  336. (default . bibtex-completion-format-citation-default)))
  337.  
  338. ;; Set up for lorem-ipsum
  339.  
  340. (require 'lorem-ipsum)
  341.  
  342. (global-set-key (kbd "C-c M-l s") 'lorem-ipsum-insert-sentences)
  343. (global-set-key (kbd "C-c M-l p") 'lorem-ipsum-insert-paragraphs)
  344. (global-set-key (kbd "C-c M-l l") 'lorem-ipsum-insert-list)
  345.  
  346.  
  347. ;;
  348. ;; **ORG-MODE SETTINGS **
  349. ;;
  350.  
  351. ;;
  352. ;; Activate Org-mode
  353. ;;
  354.  
  355. ;; (require 'org)
  356. ;; (define-key global-map "\C-cl" 'org-store-link)
  357. ;; (define-key global-map "\C-ca" 'org-agenda)
  358. ;; (define-key global-map "\C-cc" 'org-capture)
  359. ;; (define-key global-map "\C-cb" 'org-switchb)
  360.  
  361. (require 'org)
  362. (global-set-key "\C-cl" 'org-store-link)
  363. (global-set-key "\C-ca" 'org-agenda)
  364. (global-set-key "\C-cc" 'org-capture)
  365. (global-set-key "\C-cb" 'org-switchb)
  366.  
  367. (setq org-log-done t)
  368.  
  369. ;;
  370. ;; Open org agenda (todo.org) automatically
  371. ;;
  372.  
  373. (find-file "~/Documents/org/todo.org")
  374.  
  375. ;;
  376. ;; Enable opening org-agenda with "C-c a" globally
  377. ;;
  378.  
  379. (global-set-key (kbd "C-c a") 'org-agenda)
  380.  
  381.  
  382. ;; Enable transient mark mode
  383. (transient-mark-mode 1)
  384.  
  385. ;; Set the workflow-states
  386. (setq org-todo-keywords
  387. '((sequence "TODO" "IN-PROGRESS" "WAITING" "DONE")))
  388.  
  389.  
  390. ;;
  391. ;; Set variable org-agenda-files (where TODOs will be searched for)
  392. ;;
  393.  
  394. (setq org-agenda-files (list "~/Documents/org/gtd.org"
  395. "~/Documents/org/journal.org"
  396. "~/Documents/org/todo.org"
  397. "~/Documents/org/notes.org"))
  398.  
  399. ;;
  400. ;; Set visual line mode for org (aimed mainly at setting it for capture)
  401. ;;
  402.  
  403. (add-hook 'org-mode-hook #'visual-line-mode)
  404. (add-hook 'org-capture-mode-hook #'visual-line-mode)
  405.  
  406. ;;
  407. ;; Set up a capture location
  408. ;;
  409.  
  410. (setq org-default-notes-file (concat org-directory "~/Documents/org/notes.org"))
  411. (define-key global-map "\C-cc" 'org-capture)
  412.  
  413. ;;
  414. ;; Capture templates
  415. ;;
  416.  
  417. (setq org-capture-templates
  418. '(("t" "Todo" entry (file+headline "~/Documents/org/gtd.org" "Tasks")
  419. "* TODO %?\n %i\n %a")
  420. ("n" "Note" entry (file+datetree "~/Documents/org/notes.org" "Observations")
  421. "* %?\nEntered on %U\n %a")
  422. ("b" "Book" entry (file+datetree "~/Documents/org/notes.org" "Books read")
  423. "* Book finished: %?\nEntered on %U\n %a")
  424. ("v" "Video" entry (file+datetree "~/Documents/org/notes.org" "Films and shows watched")
  425. "* Film or show watched: %?\nEntered on %U\n %a")
  426. ("a" "Articles" entry (file+datetree "~/Documents/org/notes.org" "Articles of note")
  427. "* Article to note: %?\nEntered on %U\n %a")
  428. ("j" "Journal Entry"
  429. entry (file+datetree "~/Documents/org/journal.org")
  430. "* Event: %?\n\n %i\n\n From: %a"
  431. :empty-lines 1)
  432. ))
  433.  
  434.  
  435. ;; ("j" "Journal" entry (file+datetree "~/Documents/org/journal.org")
  436. ;; "* %?\nEntered on %U\n %a")))
  437.  
  438. ;;
  439. ;; Set-up refile target (will look at top three layers of headings in org-agenda-files
  440. ;;
  441.  
  442. ;; (setq org-refile-targets '((org-agenda-files :maxlevel . 3)))
  443.  
  444. (setq org-refile-targets (quote (("archive.org" :maxlevel . 2)
  445. )))
  446.  
  447. ;; Macros
  448.  
  449. (fset 'macro-add-comment
  450. (kmacro-lambda-form [?\[ ?/ ?/ ?\] ?: ?\S- ?# ? ?\( ?\) left] 0 "%d"))
  451. (global-set-key "\C-x\C-kc" 'macro-add-comment)
  452.  
  453. ;; AUCTeX set-up
  454. (setq TeX-auto-save t)
  455. (setq TeX-parse-self t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement