-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsc-garbage.el
69 lines (57 loc) · 2.38 KB
/
fsc-garbage.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
;;; fsc-garbage.el --- -*- lexical-binding: t; -*-
(require 'cl)
(setq fsc-garbage-chars "`~!@#$%^&*()_+[]{}'\"|/?<>")
(setq fsc-garbage-chars-html "`~!@#$%^&*()_+[]{}'\|/?<>")
(defun fsc-garbage (text)
(substring-no-properties
(mapconcat
(lambda (x)
(concat (string x)
(string (aref fsc-garbage-chars (random (length fsc-garbage-chars))))))
(string-to-list text) "") 0 -1))
(defun fsc-garbage-aph (text)
(mapconcat
(lambda (x) (string x)) (string-to-list text) "/"))
(defun fsc-garbage-html (text)
(replace-regexp-in-string
"\\(\\(?:.\\|\n\\)*\\)<span style='color:#fff;'>.+?</span>$" "\\1" ;remove the last char in the output
(mapconcat
(lambda (line)
(mapconcat
(lambda (x)
(concat (string x)
(concat
"<span style='color:#fff;'>"
(let ((c (string (aref fsc-garbage-chars-html (random (length fsc-garbage-chars-html))))))
(cond ((equal c "<") "<")
((equal c ">") ">")
(t c)))
"</span>")))
(string-to-list line) "")
)
(split-string-and-unquote text "\n") "<br>")))
(defun fsc-garbage-remove (text)
(if (string-match "<span style='color:#fff;'>.*?</span>" text)
(replace-regexp-in-string "<span style='color:#fff;'>.*?</span>" ""
(replace-regexp-in-string "<br>" "\n" text))
(let ((fin ""))
(do ((n 0 (+ n 2)))
((> n (1- (length text))) fin)
(setq fin (concat fin (string (aref text n))))))))
(defmacro fsc-garbage-def (funcname)
`(progn
(defun ,(intern (concat "fsc/" funcname "-region")) (begin end)
(interactive "r")
(insert (,(intern (concat "fsc-" funcname)) (delete-and-extract-region begin end))))
(defun ,(intern (concat "fsc/" funcname "-region-and-copy")) (begin end)
(interactive "r")
(kill-new (,(intern (concat "fsc-" funcname)) (buffer-substring-no-properties begin end)))
(message "Copied."))
(defun ,(intern (concat "fsc/" funcname "-minibuffer")) (text)
(interactive "sInput text: ")
(insert (,(intern (concat "fsc-" funcname)) text)))))
(fsc-garbage-def "garbage")
(fsc-garbage-def "garbage-aph")
(fsc-garbage-def "garbage-html")
(fsc-garbage-def "garbage-remove")
(provide 'fsc-garbage)