-
Notifications
You must be signed in to change notification settings - Fork 0
/
abbrevs.el
207 lines (183 loc) · 6.01 KB
/
abbrevs.el
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
;;===============;;
;; Abbreviations ;;
;;===============;;
;; Org mode
(progn
(when (boundp 'org-mode-abbrev-table)
(clear-abbrev-table org-mode-abbrev-table))
(define-abbrev-table 'org-mode-abbrev-table
'(
("zbs" "#+begin_src" nil 0)
("zes" "#+end_src" nil 0)
("zbx" "#+begin_example" nil 0) ;; Begin eXample
("zex" "#+end_example" nil 0)
("zse" "#+begin_src emacs-lisp\n\n#+end_src" nil 0)
("zxe" "#+begin_example emacs-lisp\n\n#+end_example" nil 0)
("zsr" "#+begin_src R\n\n#+end_src" nil 0)
("zxr" "#+begin_example R\n\n#+end_example" nil 0)
("zsp" "#+begin_src python\n\n#+end_src" nil 0)
("zxp" "#+begin_example python\n\n#+end_example" nil 0)
("zsc" "#+begin_src perl\n\n#+end_src" nil 0) ;; Perl is the cammel language (hence C)
("zxc" "#+begin_example perl\n\n#+end_example" nil 0)
("bahai" "bahá’í" nil 0)
)))
;; EShell
(progn
(when (boundp 'eshell-mode-abbrev-table)
(clear-abbrev-table eshell-mode-abbrev-table))
(define-abbrev-table 'eshell-mode-abbrev-table
'(
("ct" "ctags -e -R -f TAGS ." nil 0)
("ctl" "ctags -e -R -f TAGS --languages=" nil 0)
)))
;; Elisp
(progn
(when (boundp 'elisp-mode-abbrev-table)
(clear-abbrev-table elisp-mode-abbrev-table))
(define-abbrev-table 'elisp-mode-abbrev-table
'(
("gsk" "(global-set-key (kbd \"" nil 0)
("usp" "(use-package " nil 0)
("dlk" "(me/leader-keys \"" nil 0)
)))
;; Python
(progn
(when (boundp 'python-mode-abbrev-table)
(clear-abbrev-table python-mode-abbrev-table))
(define-abbrev-table 'python-mode-abbrev-table
'(
("zis" "import sys" nil 0)
("zio" "import os" nil 0)
("zit" "from typing import Optional" nil 0)
("zim" "import multiprocessing as mp" nil 0)
("zil" "import logging\n\nlogger = logging.getLogger(__name__)" nil 0)
("zmain" "if __name__ == \"__main__\":\n")
("zs" "(self, " nil 0)
)))
;; R
(progn
(when (boundp 'ess-r-mode-abbrev-table)
(clear-abbrev-table ess-r-mode-abbrev-table))
(define-abbrev-table 'ess-r-mode-abbrev-table
'(
("iis" "<-" nil 0)
("ggp" "plot <- ggplot" nil 0)
("ggs" "ggsave" nil 0)
("fun" "function" nil 0)
("dafa" "data.frame" nil 0)
)))
;; Fortran
(progn
(when (boundp 'fortran-mode-abbrev-table)
(clear-abbrev-table fortran-mode-abbrev-table))
(define-abbrev-table 'fortran-mode-abbrev-table
'(
("iii" "integer, intent(in) :: " nil 0)
("rii" "real(dp), intent(in) :: " nil 0)
("iio" "integer, intent(out) :: " nil 0)
("rio" "real(dp), intent(out) :: " nil 0)
("iib" "integer, intent(inout) :: " nil 0)
("rib" "real(dp), intent(inout) :: " nil 0)
("int" "integer" nil 0)
("rdp" "real(dp)" nil 0)
("alc" "allocatable" nil 0)
("fun" "function" nil 0)
)))
;; LaTeX
(progn
(when (boundp 'latex-mode-abbrev-table)
(clear-abbrev-table latex-mode-abbrev-table))
(define-abbrev-table 'latex-mode-abbrev-table
'(
("zla" "\label" nil 0)
("zca" "\caption" nil 0)
("zi" "^{(i)}" nil 0)
("zj" "^{(j)}" nil 0)
("zk" "^{(k)}" nil 0)
("zn" "^{(n)}" nil 0)
("zm" "^{(m)}" nil 0)
("zrr" "\in \mathcal{R}" nil 0)
("zrn" "\in \mathcal{R}^n" nil 0)
)))
;;=============;;
;; Boilerplate ;;
;;=============;;
(defun boilerplate/py-sql-connecurrent ()
(interactive)
(insert "
def execute_sql_concurrently(
db_path: str,
query: Optional[str] = None,
commit: Optional[bool] = False,
fetchone: Optional[bool] = False,
max_tries: Optional[int] = 10,
timeout: Optional[int] = 10,
) -> tuple:
\"\"\"Executes an SQL command concurrently
Args:
db_path (str) : Path to SQLite3 database.
query (str, optional) : Query to execute.
df_table (str, optional) : Table to write to if dataframe is present.
commit (bool, optional) : If True, will perform a commit after the query.
fetchone (bool, optional) : If True, will return only the first result.
Defaults to False.
max_tries (int, optional) : Maximum number of retries for SQL connection
If <0, will perpetually retry. Defaults to -1.
timeout (int, optional) : Timeout for SQLite connection in seconds.
Defaults to 10
Returns:
result (list) : Result from the SQL query.
\"\"\"
db_opt_sucessful = False
tries = -1
while not db_opt_sucessful:
tries += 1
try:
con = sqlite3.connect(db_path, timeout=timeout)
if query is not None:
cursor = con.cursor()
cursor.execute(query)
if fetchone:
result = cursor.fetchone()[0]
else:
result = cursor.fetchall()
if commit:
con.commit()
con.close()
db_opt_sucessful = True
except sqlite3.OperationalError:
if tries >= max_tries and max_tries >= 0:
logger.critical(
\"Maximum SQLite3 tries exceed \"
f\"({tries}/{max_tries})\"
)
raise
return result"))
(defun boilerplate/py-argparser ()
(interactive)
(insert "
parser = argparse.ArgumentParser(
description=\"\"
)
args = parser.parse_args()"))
(defun boilerplate/py-parser-add-arg ()
(interactive)
(insert "
parser.add_argument(
\"--arg\",
default=None,
type=int,
help=\"\",
)"))
(defun boilerplate/py-parser-add-log ()
(interactive)
(insert "
parser.add_argument(
\"--log\",
default=\"warning\",
type=str,
help=\"Log level, can be debug, info, warning, error or critical.\",
)
args = parser.parse_args()
log_level = getattr(logging, args.log.upper())
logging.basicConfig(level=log_level)"))