blob: 93caa50400a904d88e453362ae10888fc7c5e2f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#+TITLE: Personal module
* Preclude
Personal functionality or variables that aid my workflow or are just cool.
* Variables
Some user variables
#+BEGIN_SRC elisp
(setq user-full-name "Aryadev Chavali"
user-mail-address "aryadevchavali1@gmail.com")
#+END_SRC
* Reload
Reload the doom session by brute force fully loading the "config.el" file in the
doom private directory.
#+BEGIN_SRC elisp
(defun dx:reload ()
"Reload instance of doom"
(interactive)
(load-file (concat doom-private-dir "config.el")))
#+END_SRC
* Change theme
Allow user to set a theme from a limited set of candidates, based on
"dx:theme-list".
- Themes sanctioned by me:
- doom-solarized-dark: just the right everything. best for day.
- doom-gruvbox: good contrast, better for night.
- doom-city-lights: Eh contrast, quite dark
- doom-outrun-electric: Interesting colour palette
- doom-vibrant: Good contrast, bit lighter
- doom-molokai: hacker style
- doom-solarized-light: Light orange theme that's actually okay on the eyes
- doom-acario-light: Light theme with not bad colours
- Themes not sanctioned:
- Light themes other than solarized-light and acario
- Horrid low contrast ones with no colour. Grayscale particularly. I can't
handle those.
#+BEGIN_SRC elisp
(setq dx:themes/theme-list '(doom-solarized-dark
doom-gruvbox doom-city-lights
doom-outrun-electric doom-vibrant doom-molokai
doom-solarized-light doom-acario-light
base16-3024 base16-classic-dark base16-material-vivid))
(defun dx:themes/set-new-theme ()
"Set the theme from my own selection, mutate as you see fit"
(interactive)
(let ((theme (completing-read "Select theme: " dx:themes/theme-list)))
(condition-case nil
(progn
(mapc #'disable-theme custom-enabled-themes)
(load-theme (intern theme) t)
(when (fboundp 'powerline-reset)
(powerline-reset)))
(error "Problem loading theme %s" theme))))
#+END_SRC
* Password store
Function to get a password given a key.
#+BEGIN_SRC elisp
(defun dx:password-store/get-password (KEY)
(shell-command-to-string (concat "pass " KEY)))
#+END_SRC
* Weather
Function to quickly check weather, which is what I wanted wttrin for.
#+BEGIN_SRC elisp
(defun dx:weather ()
"Check the weather at the 'location' stored in password store"
(interactive)
(wttrin (dx:password-store/get-password "location")))
#+END_SRC
* Newline
Insert a newline without having to exit normal mode!
#+BEGIN_SRC elisp
(defun dx:newline (&optional BACKWARD)
(interactive)
(message "%s" BACKWARD)
(let ((old (point)))
(cond ((and BACKWARD (= BACKWARD 1)) (+default/newline-above))
(t (+default/newline-below)))
(goto-char (+ old 1))
(evil-normal-state)))
#+END_SRC
* Convert auto-fill lines to long truncate-lines
Consider some org file with auto filled lines.
I don't like auto-filled lines.
So I want to convert them.
I've setup macros countless times to do this operation for me, may as well formalize it as a function.
Firstly, I need a function to count the number of instances of some substring occur in some other string.
Shamelessly copied from rosetta code.
#+BEGIN_SRC elisp
(defun dx:org/count-sub (str pat)
(loop with z = 0 with s = 0 while s do
(when (setf s (search pat str :start2 s))
(incf z) (incf s (length pat)))
finally (return z)))
#+END_SRC
Then the main function, works like so:
1) Search the text in the region for newlines then join the lines to make a single segment
2) Search for sentences through Emacs builtin =forward-sentence= and =forward-char= functions then newline via sentences
#+BEGIN_SRC elisp
(defun dx:org/fill-to-long-lines ()
(interactive)
(let* ((beg (region-beginning))
(end (region-end))
(region-text (buffer-substring-no-properties beg end))
(n-sentences (dx:org/count-sub region-text "."))
(parsed-text (apply #'concatenate 'string (cl-loop for c from beg to end collect
(if (string= (buffer-substring-no-properties c (+ c 1)) "\n") " "
c)))))
(delete-region beg end)
(insert parsed-text)
(message "%s" n-sentences)
(evil-normal-state)
(evil-digit-argument-or-evil-beginning-of-line)
(cl-loop for i from 1 to n-sentences do (forward-sentence) (forward-char) (newline))))
#+END_SRC
|