-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoload.el
More file actions
214 lines (192 loc) · 6.88 KB
/
Copy pathautoload.el
File metadata and controls
214 lines (192 loc) · 6.88 KB
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
208
209
210
211
212
213
214
;;; autoload.el --- autoload file of my private module
;; Copyright 2018 Binjo
;;
;; Author: Binjo
;; Version: $Id: autoload.el,v 0.0 2018/07/18 05:49:25 binjo Exp $
;; Keywords:
;; X-URL: not distributed yet
;;; Commentary:
;;
;;;###autoload
(defun binjo/org-capture-todo ()
(interactive)
(org-capture nil "t"))
;;;###autoload
(defun binjo/org-capture-remember ()
(interactive)
(org-capture nil "c"))
;;;###autoload
(defun binjo-unify-line (begin end)
"wipe out the same line of specified region"
(interactive "r")
(goto-char begin)
(let ((line "")
(unified ()))
(save-excursion
(while (not (eobp))
(setq line (downcase (buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
(unless (assoc-string line unified)
(if (null unified)
(setq unified (list (cons line 1)))
(setq unified (append (list (cons line 1)) unified))))
(forward-line))
(pop-to-buffer (get-buffer-create "*unified-line*"))
(erase-buffer)
(mapc (lambda (x)
(insert (car x))
(insert "\n")) (reverse unified)))))
;;
;; eshell utils
;;
;;;###autoload
(defun eshell/cls()
"Clearing EShell Buffer."
(interactive)
(let ((inhibit-read-only t))
(erase-buffer)))
;;;###autoload
(defun eshell/url (lru)
"Decrypt LRU(url) from %u7468%u7074%u2f3a to 'http:/'."
(interactive)
(let ((a_url (split-string lru "%u"))
(a ""))
(mapc (lambda (x)
(unless (string= x "")
(unless (string= (substring x 2 4) "00")
(setq a (concat a (format "%c" (string-to-number (substring x 2 4) 16)))))
(unless (string= (substring x 0 2) "00")
(setq a (concat a (format "%c" (string-to-number (substring x 0 2) 16)))))))
a_url)
(kill-new a t)
a))
;;;###autoload
(defun eshell/unhex (hex-string)
"Convert hexlified HEX-STRING to normal."
(interactive)
(let ((a "")
(i 0)
(len (length hex-string)))
(while (< i len)
(setq a (concat a (format "%c" (string-to-number (substring hex-string i (+ i 2)) 16))))
(setq i (+ i 2)))
(kill-new a t)
a))
;;;###autoload
(defun eshell/hex (string)
"Convert STRING to hex, a.k.a hexlify."
(interactive)
(let ((hexlified "")
(a_s (string-to-list string)))
(mapc (lambda (x)
(setq hexlified (concat hexlified
(format "%02x" x))))
a_s)
(kill-new hexlified t)
hexlified))
;;;###autoload
(defun eshell/h2b (file-name hex)
"Convert encoded HEX to binary, save as FILE-NAME."
(interactive)
(let ((a_h (split-string hex "%u"))
(coding-system-for-write 'raw-text-unix))
(with-temp-file file-name
(mapc (lambda (x)
(unless (string= x "")
(insert-byte (string-to-number (substring x 2 4) 16) 1)
(insert-byte (string-to-number (substring x 0 2) 16) 1)))
a_h))
"[*] Done...Check it out..."))
;;;###autoload
(defun eshell/a2b (file-name asciis)
"Convert encoded ASCIIS to binary, save as FILE-NAME."
(interactive)
(let ((len (length asciis))
(coding-system-for-write 'raw-text-unix)
(i 0))
(if (eq 0 (% len 2))
(progn
(with-temp-file file-name
(while (< i len)
(insert-byte (string-to-number (substring asciis i (+ i 2)) 16) 1)
(setq i (+ i 2))))
"[+] Done, check it out...")
"[-] shit, length even? ...")))
;;;###autoload
(defun binjo/refile-to-roam-file (arg file)
"Refile current heading to a particular org roam file."
(interactive
(list current-prefix-arg
(ivy-completing-read "Select file to refile to: "
'read-file-name-internal
'file-exists-p
nil org-directory)))
(+org/refile-to-current-file arg file))
;;;###autoload
(defun binjo/refile-to-roam-file-2 (arg file)
"Refile current heading to org roam file."
(interactive
(list current-prefix-arg
(plist-get (cdr (assoc (org-roam-completion--completing-read "File: " (org-roam--get-title-path-completions))
(org-roam--get-title-path-completions))) :path)))
(+org/refile-to-current-file arg file))
;;;###autoload
(defun binjo/refile-to-roam-today-file (arg file)
"Refile current heading to org roam today file."
(interactive
(list current-prefix-arg
(expand-file-name (format-time-string "%Y-%m-%d.org")
(concat
(file-name-as-directory org-roam-directory)
org-roam-dailies-directory))))
(+org/refile-to-current-file arg file))
;; copy&renamed from https://github.com/telotortium/doom.d/blob/f0295cc510d31c813e2a61ab2fc4aad3ae531e49/org-config.el#L1250-L1271
;; let user decide if certain part should be stripped
;;;###autoload
(defun binjo/refile-from-headline ()
"Create an Org-roam note from the current headline and jump to it.
Normally, insert the headline’s title using the ’#title:’ file-level property
and delete the Org-mode headline. However, if the current headline has a
Org-mode properties drawer already, keep the headline and don’t insert
‘#+title:'. Org-roam can extract the title from both kinds of notes, but using
‘#+title:’ is a bit cleaner for a short note, which Org-roam encourages."
(interactive)
(let ((title (nth 4 (org-heading-components)))
(has-properties (org-get-property-block)))
(org-cut-subtree)
(org-roam-find-file title nil nil 'no-confirm)
(org-paste-subtree)
(unless has-properties
;; (kill-line)
(while (outline-next-heading)
(org-promote)))
(goto-char (point-min))
(outline-next-heading)))
;;;###autoload
(defun binjo/convert-to-org-element (beg end)
"Convert the selected region to an Org-mode friendly element.
1. Prepends a comma to lines starting with '*'.
2. Wraps sections starting with '# **[b/' in a Markdown source block.
3. Collapses multiple empty or whitespace-only lines into one."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region beg end)
;; Step 1: Replace multiple empty/whitespace lines with a single newline
(goto-char (point-min))
(while (re-search-forward "\n\\([ \t]*\n\\)\\{2,\\}" nil t)
(replace-match "\n\n"))
;; Step 2: Escape lines starting with *
(goto-char (point-min))
(while (re-search-forward "^\\*" nil t)
(replace-match ",*"))
;; Step 3: Wrap specific Markdown patterns
(goto-char (point-min))
(while (re-search-forward "^# \\*\\*\\[b/" nil t)
(beginning-of-line)
(insert "#+BEGIN_SRC markdown\n")
(beginning-of-line)
(goto-char (point-max))
(insert "#+END_SRC\n"))
(message "Conversion complete."))))
;;; autoload.el ends here