summaryrefslogtreecommitdiff
path: root/modules/custom-functions.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-08 17:16:29 -0500
committerCraig Jennings <c@cjennings.net>2024-04-08 17:16:29 -0500
commita55a5248bd2dae5f849476d0f7b5dcd8d91cf929 (patch)
tree834a7b012f6823b53ee2f516384b7bc4c4ec819b /modules/custom-functions.el
parent754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (diff)
fit and finish work
- gptel: added gptel-send-region with global keybinding - projectile: made project-switch-actions more efficient with regexp - prog-go: removed disabled code - mu4e: capture template captures region if selected - system utils: merged bury alive with other killing buffer code - org-capture: renamed *website-clipper to org-webpage-clipper - rg: auto switch to ripgrep-results window when ripgrep search completes - dashboard: remove dashboard banner custom face General - moved abbrev_defs to assets - removed gitmodules file - updated packages - fixed docstring and formatting throughout Custom-Functions - move cj/merge-list-to-list to custom-functions - add remove leading trailing whitespace function - corrected arrayify prompt Font-Config - added font point sizes in fontaine menu - make default font point size 11 Python - adding back python poetry support - added cj/python-setup method - merge python and python-mode configurations (they are the same built-in package) Show-Kill-Ring - show-kill-ring displays in another read-only buffer - show-kill-ring exits with q Elfeed - moved elfeed-feeds.org to assets - removed Wired from elfeed feeds - moved ElfeedDB to user-emacs-directory/.elfeed-db - moved elfeed-dashboard.org to assets
Diffstat (limited to 'modules/custom-functions.el')
-rw-r--r--modules/custom-functions.el67
1 files changed, 51 insertions, 16 deletions
diff --git a/modules/custom-functions.el b/modules/custom-functions.el
index fe617ed1..414d3108 100644
--- a/modules/custom-functions.el
+++ b/modules/custom-functions.el
@@ -130,6 +130,32 @@ buffer."
(indent-region start-pos end-pos nil)
(untabify start-pos end-pos))))
+;; ------------------- Remove Leading And Trailing Whitespace ------------------
+;; removes leading and trailing whitespace on line, region, or buffer.
+
+(defun cj/remove-leading-trailing-whitespace (start end)
+ "Remove leading and trailing whitespace in a region or buffer.
+When called interactively, if a region is active, remove leading
+and trailing spaces in the region. Else, remove from the current line.
+If called with a prefix argument (C-u), remove throughout the entire buffer.
+START and END define region."
+ (interactive "r")
+ (let (deactivate-mark)
+ (if (or (use-region-p) current-prefix-arg)
+ (save-restriction
+ (if current-prefix-arg
+ (progn (widen) (setq start (point-min) end (point-max)))
+ (narrow-to-region start end))
+ (goto-char (point-min))
+ (while (re-search-forward "^[ \t]+" nil t) (replace-match ""))
+ (goto-char (point-min))
+ (while (re-search-forward "[ \t]+$" nil t) (replace-match "")))
+ (beginning-of-line)
+ (while (looking-at "^[ \t]+") (replace-match ""))
+ (end-of-line)
+ (while (re-search-backward "[ \t]+$" (line-beginning-position) t)
+ (replace-match "")))))
+
;; --------------------------- Arrayify / Unarrayify ---------------------------
;; unquoted text on newlines to quoted comma separated strings (and vice-versa).
@@ -137,7 +163,7 @@ buffer."
"Turn unquoted text on newlines into quoted comma-separated strings.
START and END indicate the region selected.
QUOTE is the characters used for quotations (i.e, \=' or \")"
- (interactive "r\nMQuote: ")
+ (interactive "r\nMQuotation character to use for array element: ")
(let ((insertion
(mapconcat
(lambda (x) (format "%s%s%s" quote x quote))
@@ -456,7 +482,16 @@ Uses `sortable-time-format' for the formatting the date/time."
(defadvice align-regexp (around align-regexp-with-spaces activate)
"Avoid tabs when aligning text."
(let ((indent-tabs-mode nil))
- ad-do-it))
+ ad-do-it))
+
+;; ----------------------------- Merge List To List ----------------------------
+;; Convenience method for merging two lists together
+;; https://emacs.stackexchange.com/questions/38008/adding-many-items-to-a-list/68048#68048
+
+(defun cj/merge-list-to-list (dst src)
+ "Merge content of the 2nd list SRC with the 1st one DST."
+ (set dst
+ (append (eval dst) src)))
;; ------------------------------ Personal Keymap ------------------------------
;; a keymap to use the above functions. prefix key: "C-;"
@@ -472,20 +507,20 @@ Uses `sortable-time-format' for the formatting the date/time."
(define-key map "D" 'cj/remove-duplicate-lines-from-region-or-buffer)
(define-key map ")" #'cj/jump-to-matching-paren)
- (define-key map "-" #'cj/hyphenate-whitespace-in-region)
- (define-key map "p" 'cj/append-to-lines-in-region-or-buffer)
- (define-key map "1" 'cj/alphabetize-and-replace-regibon)
- (define-key map "C" 'display-fill-column-indicator-mode)
- (define-key map "w" 'cj/wrap-region-as-code-span)
- (define-key map "f" 'cj/format-region-or-buffer)
- (define-key map "h" 'cj/hyphenate-region)
- (define-key map "j" 'cj/join-line-or-region)
- (define-key map "J" 'cj/join-paragraph)
- (define-key map "r" 'align-regexp)
- (define-key map "l" 'downcase-dwim)
- (define-key map "u" 'cj/title-case-region)
- (define-key map "U" 'upcase-region)
- (define-key map "#" 'cj/count-words-buffer-or-region)
+ (define-key map "-" #'cj/hyphenate-region)
+ (define-key map "U" 'upcase-region)
+ (define-key map "w" 'cj/remove-leading-trailing-whitespace)
+ (define-key map "#" 'cj/count-words-buffer-or-region)
+ (define-key map "1" 'cj/alphabetize-and-replace-region)
+ (define-key map "C" 'display-fill-column-indicator-mode)
+ (define-key map "J" 'cj/join-paragraph)
+ (define-key map "f" 'cj/format-region-or-buffer)
+ (define-key map "j" 'cj/join-line-or-region)
+ (define-key map "l" 'downcase-dwim)
+ (define-key map "p" 'cj/append-to-lines-in-region-or-buffer)
+ (define-key map "r" 'align-regexp)
+ (define-key map "u" 'cj/title-case-region)
+ (define-key map "c" 'cj/wrap-region-as-code-span)
map)
"My personal key map.")
(global-set-key (kbd "C-;") personal-keymap)