emacs.d/bundle/bundle--mk.el

187 lines
6.4 KiB
EmacsLisp
Raw Normal View History

2022-08-24 19:34:56 +02:00
(defvar mk/useful-websites
'(("https://regexr.com/" regex debug)
("https://regex101.com/" regex debug)
("https://www.regextester.com/" regex debug)
("https://extendsclass.com/regex-tester.html#python" regex debug)
("https://everything.curl.dev/" curl tool)))
(defvar mk/mirror-website
"Locally mirror a website using `wget -mkEpnp <url>`")
(defvar mk/useful-regex
2023-01-15 09:38:53 +01:00
'(("match any word or space that precede the :" . "[\w\s]+:")
("search for anything in square brackets" . "\[.*\]")
2022-08-24 19:34:56 +02:00
("[A-Za-z]+" "upper and lowercase english alphabet")
("[0-9]" "numbers from 0 to 9")
("[A-Za-z\-\.]" "upper and lowercase english alphabet, - and .")
("(a-z)" "a, - and z")
("(\s+|,)" "spaces or a comma")
("#\w+" "find hashtags")
("([@|#]\w+)" "matches both mentions (@) and hashtags")
("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)" "email regex")
("-?\d+(\.\d*)?" "matching decimal numbers")
("(?:http|https|ftp|mailto|file|data|irc):\/\/[A-Za-z0-9\-]{0,63}(\.[A-Za-z0-9\-]{0,63})+(:\d{1,4})?\/*(\/*[A-Za-z0-9\-._]+\/*)*(\?.*)?(#.*)?" "matching urls")
("^\d{4}/(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])$" "matching dates yyyy/mm/dd")
("^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/\d{4}$" "matching dates mm/dd/yyyy")
("^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\d{4}$" "matching dates dd/mm/yyyy")
("<.+>" "matching html")
("<\/?(?:p|a|b|img)(?: \/)?>" "matchig specific tags")))
2022-05-06 19:55:40 +02:00
;; (defun mk-show-modeline ()
;; (interactive)
;; (setq mode-line-format
;; '(("-" mode-line-mule-info
;; mode-line-modified
;; mode-line-frame-identification
;; mode-line-buffer-identification " "
;; mode-line-position
;; mode-line-modes
;; (which-func-mode
;; ("" which-func-format "--"))
;; (global-mode-string
;; ("--" global-mode-string)) "-%-")))
;; (defvar mode-line-format-current
;; (symbol-value 'mode-line-format)))
2020-11-25 08:58:30 +01:00
2022-05-06 19:55:40 +02:00
;; (defun mk-hide-modeline ()
;; (interactive)
;; (setq mode-line-format nil))
2020-11-25 08:58:30 +01:00
2022-05-06 19:55:40 +02:00
;; (defun mk-write-mode-enable ()
;; (setq olivetti-body-width 73)
;; (olivetti-mode)
;; (mk-hide-modeline))
2020-11-25 08:58:30 +01:00
2022-05-06 19:55:40 +02:00
;; (defun mk-write-mode-disable ()
;; (olivetti-mode)
;; (mk-show-modeline))
2020-08-20 10:41:09 +02:00
2022-08-24 19:34:56 +02:00
(defun mk/split-windows-horizontal (count-windows)
2020-08-20 10:41:09 +02:00
"Split windows horizontal by equal width."
2021-06-01 16:43:37 +02:00
(interactive "nHow many splits? ")
2020-08-20 10:41:09 +02:00
(delete-other-windows)
(let ((width (/ (window-total-width) count-windows)))
2021-06-05 16:56:43 +02:00
(dotimes (i (1- count-windows))
(split-window-right (- width)))))
2022-08-24 19:34:56 +02:00
(defun mk/split-windows-vertical (count-windows)
2021-06-05 16:56:43 +02:00
"Split windows vertical by equal width."
(interactive "nHow many splits? ")
(delete-other-windows)
(let ((height (/ (window-total-height) count-windows)))
(dotimes (i (1- count-windows))
(split-window-below (- height)))))
2021-06-01 16:43:37 +02:00
2022-08-24 19:34:56 +02:00
(defun mk/split-h3 ()
2021-06-01 16:43:37 +02:00
(interactive)
2022-08-24 19:34:56 +02:00
(mk/split-windows-horizontal 3))
2020-08-20 10:41:09 +02:00
2022-08-24 19:34:56 +02:00
(defun mk/split-v3 ()
2020-08-20 10:41:09 +02:00
(interactive)
2022-08-24 19:34:56 +02:00
(mk/split-windows-vertical 3))
;; Set transparency of emacs
(defun transparency (value)
"Sets the transparency of the frame window. 0=transparent/100=opaque"
(interactive "nTransparency Value 0 - 100 opaque: ")
(set-frame-parameter (selected-frame) 'alpha value))
2021-06-02 09:39:34 +02:00
2022-08-24 19:34:56 +02:00
(defun mk/show-agenda-list ()
(if (display-graphic-p)
(add-hook 'after-init-hook (lambda () (org-agenda-list) (me/split-h3)))
(org-agenda-list)))
2022-08-13 12:30:46 +02:00
2022-08-24 19:34:56 +02:00
(defun mk/list-files (folder suffix)
2022-08-13 18:43:20 +02:00
(let ((regexp (concat "\\." suffix "$")))
(directory-files folder nil regexp)))
2022-08-24 19:34:56 +02:00
(defun mk/build-file-suffix ())
2022-08-13 12:30:46 +02:00
2022-08-24 19:34:56 +02:00
(defun mk/copy-files (src-dir dst-dir suffix)
2022-08-13 12:30:46 +02:00
(let ((src-files '())
(src-dir (expand-file-name src-dir))
(dst-dir (expand-file-name dst-dir)))
2022-08-24 19:34:56 +02:00
(dolist (file (mk/list-files src-dir suffix) src-files)
2022-08-13 12:30:46 +02:00
(let ((src-file (expand-file-name (concat src-dir "/" file)))
(dst-file (expand-file-name (concat dst-dir "/" file))))
(add-to-list 'src-files src-file)
(copy-file src-file dst-file t)))))
2022-08-24 19:34:56 +02:00
(defun mk/delete-files (lst)
2022-08-13 12:30:46 +02:00
(dolist (file lst)
(delete-file file t)))
2023-01-06 12:44:39 +01:00
;; (defun shr-insert (text)
;; (when (and (not (bolp))
;; (get-text-property (1- (point)) 'image-url))
;; (insert "\n"))
;; (cond
;; ((eq shr-folding-mode 'none)
;; (let ((start (point)))
;; (insert text)
;; (save-restriction
;; (narrow-to-region start (point))
;; (shr--translate-insertion-chars)
;; (goto-char (point-max)))))
;; (t
;; (let ((font-start (point)))
;; (when (and (string-match "\\`[ \t\n\r]" text)
;; (not (bolp))
;; (not (eq (char-after (1- (point))) ? )))
;; (insert " "))
;; (let ((start (point))
;; (bolp (bolp)))
;; (insert text)
;; (save-restriction
;; (narrow-to-region start (point))
;; (goto-char start)
;; (when (looking-at "[\t\n\r]+")
;; (replace-match "" t t))
;; (while (re-search-forward "[\t\n\r]+" nil t)
;; (replace-match " " t t))
;; (goto-char start)
;; (while (re-search-forward " +" nil t)
;; (replace-match " " t t))
;; (shr--translate-insertion-chars)
;; (goto-char (point-max)))
;; ;; We may have removed everything we inserted if it was just
;; ;; spaces.
;; (unless (= font-start (point))
;; ;; Mark all lines that should possibly be folded afterwards.
;; (when bolp
;; (shr-mark-fill start))
;; (when shr-use-fonts
;; (put-text-property font-start (point)
;; 'face
;; (or shr-current-font 'variable-pitch)))))))))
2023-06-09 18:45:05 +02:00
(defun mk/get-current-time-formatted ()
2023-10-03 14:17:36 +02:00
(concat "#+DATE: "
(format "[%s]" (format-time-string "%Y-%m-%d %R" (current-time)))))
(defun generate-unique-id ()
(interactive)
(let ((random-number-1 (random 9999))
(random-number-2 (random 9999)))
(let ((unique-id (format "DE-%04d-%04d" random-number-1 random-number-2)))
(message "ID: %s" unique-id) unique-id)))
2023-11-12 09:28:50 +01:00
(defmacro mk/open-html-page (name path)
"Make interactive functions to call important docs"
`(defun ,name ()
(interactive)
(eww (concat "file://"
(and (eq system-type 'windows-nt)
"/")
(expand-file-name ,path)))))
(mk/open-html-page mk/clsite-clm
"~/cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node1.html")
(mk/open-html-page mk/clsite-pcl
"~/cl-sites/gigamonkeys.com/book/index.html")
(mk/open-html-page mk/clsite-clcb
"~/cl-sites/lispcookbook.github.io/cl-cookbook/index.html")
(mk/open-html-page mk/clsite-sqlite
"~/cl-sites/sqlite-doc-3440000/index.html")