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-11-12 09:29:07 +01:00
|
|
|
'(("match any word or space that precedes the :" . "[\\w\\s]+:")
|
|
|
|
("search for anything in square brackets" . "\\[.*\\]")
|
|
|
|
("upper and lowercase English alphabet" . "[A-Za-z]+")
|
|
|
|
("numbers from 0 to 9" . "[0-9]")
|
|
|
|
("upper and lowercase English alphabet, - and ." . "[A-Za-z\\-\\.]+")
|
|
|
|
("a, - and z" . "(a-z)")
|
|
|
|
("spaces or a comma" . "(\\s+|,)")
|
|
|
|
("find hashtags" . "#\\w+")
|
|
|
|
("matches both mentions (@) and hashtags" . "([@|#]\\w+)")
|
|
|
|
("email regex" . "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$")
|
|
|
|
("matching decimal numbers" . "-?\\d+(\\.\\d*)?")
|
|
|
|
("matching urls" . "(?: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 dates yyyy/mm/dd" . "^\\d{4}/(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])$")
|
|
|
|
("matching dates mm/dd/yyyy" . "^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/\\d{4}$")
|
|
|
|
("matching dates dd/mm/yyyy" . "^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\\d{4}$")
|
|
|
|
("matching HTML" . "<.+>")
|
|
|
|
("matching specific tags" . "</?(?:p|a|b|img)(?: /)?>")
|
|
|
|
("ISO 8601 Date Format (YYYY-MM-DD)" . "\\([0-9]{4}\\)-\\([0-1][0-9]\\)-\\([0-3][0-9]\\)")))
|
2022-08-24 19:34:56 +02:00
|
|
|
|
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))
|
2020-11-21 09:26:01 +01:00
|
|
|
|
2021-05-07 14:34:21 +02:00
|
|
|
;; 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)))))
|
|
|
|
|
2023-12-02 09:16:01 +01:00
|
|
|
(defun mk/generate-unique-id ()
|
2023-10-03 14:17:36 +02:00
|
|
|
(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
|
|
|
|
2024-04-02 09:59:45 +02:00
|
|
|
(defmacro mk/open-html-page (name path buffer-name)
|
2023-11-12 09:28:50 +01:00
|
|
|
"Make interactive functions to call important docs"
|
|
|
|
`(defun ,name ()
|
|
|
|
(interactive)
|
|
|
|
(eww (concat "file://"
|
|
|
|
(and (eq system-type 'windows-nt)
|
|
|
|
"/")
|
2024-04-02 09:59:45 +02:00
|
|
|
(expand-file-name ,path)))
|
|
|
|
(rename-buffer ,buffer-name)))
|
2023-11-12 09:28:50 +01:00
|
|
|
|
|
|
|
(mk/open-html-page mk/clsite-clm
|
2024-04-02 09:59:45 +02:00
|
|
|
"~/cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node1.html"
|
|
|
|
"*mk/clsite-clm*")
|
2023-11-12 09:28:50 +01:00
|
|
|
(mk/open-html-page mk/clsite-pcl
|
2024-04-02 09:59:45 +02:00
|
|
|
"~/cl-sites/gigamonkeys.com/book/index.html"
|
|
|
|
"*mk/clsite-pcl*")
|
2023-11-12 09:28:50 +01:00
|
|
|
(mk/open-html-page mk/clsite-clcb
|
2024-04-02 09:59:45 +02:00
|
|
|
"~/cl-sites/lispcookbook.github.io/cl-cookbook/index.html"
|
|
|
|
"*mk/clsite-clcb*")
|
2023-11-12 09:28:50 +01:00
|
|
|
(mk/open-html-page mk/clsite-sqlite
|
2024-04-02 09:59:45 +02:00
|
|
|
"~/cl-sites/sqlite-doc-3440000/index.html"
|
|
|
|
"*mk/clsite-sqlite*")
|
2023-11-12 11:34:41 +01:00
|
|
|
(mk/open-html-page mk/clsite-asdf
|
2024-04-02 09:59:45 +02:00
|
|
|
"~/cl-sites/asdf.common-lisp.dev/index.html"
|
|
|
|
"*mk/clsite-asdf*")
|
2024-03-13 22:59:47 +01:00
|
|
|
(mk/open-html-page mk/clsite-lisp-docs
|
2024-04-02 09:59:45 +02:00
|
|
|
"~/cl-sites/lisp-docs.github.io/index.html"
|
|
|
|
"*mk/clsite-lisp-docs*")
|
2024-04-02 13:55:27 +02:00
|
|
|
(mk/open-html-page mk/clsite-bgnet
|
|
|
|
"~/cl-sites/bgnet/index.html"
|
|
|
|
"*mk/clsite-bgnet*")
|
2024-04-06 12:07:18 +02:00
|
|
|
(mk/open-html-page mk/clsite-postgresql
|
|
|
|
"~/cl-sites/www.postgresql.org/docs/16/index.html"
|
|
|
|
"*mk/clsite-postgresql*")
|
2023-11-12 12:18:40 +01:00
|
|
|
|
|
|
|
(defun mk/wget-mirror-site (url)
|
|
|
|
"Use wget to mirror a website for offline use. Takes a URL as argument."
|
|
|
|
(interactive "sEnter the URL to mirror: ")
|
|
|
|
(let ((cmd (format "wget --mirror --convert-links --adjust-extension --page-requisites --no-parent %s" url)))
|
|
|
|
(async-shell-command cmd)))
|