emacs.d/bundle/bundle--mk.el
2024-04-02 09:59:45 +02:00

204 lines
7.3 KiB
EmacsLisp

(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
'(("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]\\)")))
;; (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)))
;; (defun mk-hide-modeline ()
;; (interactive)
;; (setq mode-line-format nil))
;; (defun mk-write-mode-enable ()
;; (setq olivetti-body-width 73)
;; (olivetti-mode)
;; (mk-hide-modeline))
;; (defun mk-write-mode-disable ()
;; (olivetti-mode)
;; (mk-show-modeline))
(defun mk/split-windows-horizontal (count-windows)
"Split windows horizontal by equal width."
(interactive "nHow many splits? ")
(delete-other-windows)
(let ((width (/ (window-total-width) count-windows)))
(dotimes (i (1- count-windows))
(split-window-right (- width)))))
(defun mk/split-windows-vertical (count-windows)
"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)))))
(defun mk/split-h3 ()
(interactive)
(mk/split-windows-horizontal 3))
(defun mk/split-v3 ()
(interactive)
(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))
(defun mk/show-agenda-list ()
(if (display-graphic-p)
(add-hook 'after-init-hook (lambda () (org-agenda-list) (me/split-h3)))
(org-agenda-list)))
(defun mk/list-files (folder suffix)
(let ((regexp (concat "\\." suffix "$")))
(directory-files folder nil regexp)))
(defun mk/build-file-suffix ())
(defun mk/copy-files (src-dir dst-dir suffix)
(let ((src-files '())
(src-dir (expand-file-name src-dir))
(dst-dir (expand-file-name dst-dir)))
(dolist (file (mk/list-files src-dir suffix) src-files)
(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)))))
(defun mk/delete-files (lst)
(dolist (file lst)
(delete-file file t)))
;; (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)))))))))
(defun mk/get-current-time-formatted ()
(concat "#+DATE: "
(format "[%s]" (format-time-string "%Y-%m-%d %R" (current-time)))))
(defun mk/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)))
(defmacro mk/open-html-page (name path buffer-name)
"Make interactive functions to call important docs"
`(defun ,name ()
(interactive)
(eww (concat "file://"
(and (eq system-type 'windows-nt)
"/")
(expand-file-name ,path)))
(rename-buffer ,buffer-name)))
(mk/open-html-page mk/clsite-clm
"~/cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node1.html"
"*mk/clsite-clm*")
(mk/open-html-page mk/clsite-pcl
"~/cl-sites/gigamonkeys.com/book/index.html"
"*mk/clsite-pcl*")
(mk/open-html-page mk/clsite-clcb
"~/cl-sites/lispcookbook.github.io/cl-cookbook/index.html"
"*mk/clsite-clcb*")
(mk/open-html-page mk/clsite-sqlite
"~/cl-sites/sqlite-doc-3440000/index.html"
"*mk/clsite-sqlite*")
(mk/open-html-page mk/clsite-asdf
"~/cl-sites/asdf.common-lisp.dev/index.html"
"*mk/clsite-asdf*")
(mk/open-html-page mk/clsite-lisp-docs
"~/cl-sites/lisp-docs.github.io/index.html"
"*mk/clsite-lisp-docs*")
(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)))