A collection of miscellaneous functions and macros, which are either candidates to migrate to a minor mode, or will languish here in perpetuity.
Peppered in here are a few gems, some redundancies and some stuff I was just playing with. They are auto-documented in this markdown document.
Items used often:...
current-buffer-defuns-to-markdown
(which generated this page.)defun-pcase
plist-bind
*-and-replace
screencapture-mac
ocodo-custom-key-bindings-to-markdown
format-multiline
Return a random element from the list
.
function signature
(-sample (list))
Align columns of numbers right in the region (begin
, end
).
For example:
10 49 1123
301 213 4111
2134 4151 525235
48912 522 19538
;; =>
;; 10 49 1123
;; 301 213 4111
;; 2134 4151 525235
;; 48912 522 19538
function signature
(align-number-right (begin end))
Save the buffer file name to the kill ring.
function signature
(buffer-file-name-to-kill-ring)
Change the number at point using func
.
It should be wrapped in an interactive function, and func should take a single numeric argument and return anything.
For example:
(defun round-number-at-point ()
"Round the number at point."
(interactive)
(change-number-at-point #'round))
;; Or...
(defun number-at-point-to-currency ()
"Change the number at point to currency."
(format "$%.2f" (number-at-point))))
function signature
(change-number-at-point (func))
Perform a cleanup operations on a buffer, tabs to spaces, re-indent, trim whitespace.
function signature
(cleanup-buffer)
Clear all text face properties in the buffer. This is somewhat useful when dealing with text pasted from a propertied buffer.
Note: this won't turn off face properties in a font-locked buffer.
function signature
(clear-buffer-text-properties)
Comments or uncomments the current line or all the lines in region.
function signature
(comment-or-uncomment-current-line-or-region)
Copy the current region to the other window.
function signature
(copy-region-or-rest-of-line-to-other-window)
Copy from cursor to end the current line to the kill ring.
function signature
(copy-rest-of-line)
Copy the current line to the kill ring.
function signature
(copy-whole-line)
Convert simple (very limited) csv
string to list of lists.
Consider this a basic experiment, which won't be developed.
Use csv-mode
instead.
For example:
(let1 csv (format-multiline
"|1, 2, 3, Words like this, #ffeeff
|2, 41, 414, 2002, Foo Bar")
(csv-to-lists csv))
;; => (("1" "2" "3" "Words like this" "#ffeeff")
;; ("2" "41" "414" "2002" "Foo Bar"))
function signature
(csv-to-lists (csv))
Display cua-rectangle-keymap in which-key.
function signature
(cua-rectangle-which-key-help)
Convert num
to hex.
function signature
(decimal-to-hex (num))
Adjust the default font :height by 10, universal argument is m
(to set by multiples).
function signature
(decrease-default-font-height (m))
Decrement number at point like vim's Ctrl x.
function signature
(decrement-number-at-point)
Delete the current frame or buffer. When there is only one frame, kill the buffer.
function signature
(delete-frame-or-window-dwim)
Delete the file connected to this buffer and kill it, force
is universal argument.
function signature
(delete-this-buffer-and-file (force))
No docstring available: TODO
function signature
(describe-thing-at-point)
In Dired, visit this file or directory in another window and remain in first window.
function signature
(dired-find-file-other-window-and-back)
Go to one of the currently open dired buffers (if there is one).
function signature
(dired-menu)
Use the OSX open
command to launch the current dired file at point.
function signature
(dired-osx-open-this-file)
Open directory with dired which contain the given libraryname
.
function signature
(dired-visit-library (libraryname))
Duplicates the current line or region arg
times.
If up
is non-nil, duplicate and move point to the top.
function signature
(duplicate-current-line-or-region (arg &optional up))
Duplicates the current line or region up arg
times.
function signature
(duplicate-current-line-or-region-up (arg))
Replace the preceding sexp with its result.
function signature
(eval-and-replace)
Replace the preceding sexp with its value using prin1.
function signature
(eval-and-replace-prin1)
Remove entries matching pattern
from recent files.
This is operating on the recentf-list
, in memory.
Use recentf-save-list
to persist.
function signature
(filter-recentf (pattern))
Flush blank lines.
function signature
(flush-blank-lines)
Convert val
of width
to a binary string.
&optional width
will default to 8.
function signature
(format-binary (val &optional width))
Format a multiline indented format-string
with args
.
A multiline string can use leading |
(pipe) characters to line
up indentation.
args
passed will populate format template tokens in the
format-string
. Tokens are as defined in (format ...)
For example:
(fomat-multiline "|- List...
| - Item %s
| - Item %#x
| - Item %x
|
|... %s"
"one" 2 #xf "the end")
=>
"- List...
- Item one
- Item 0x2
- Item f
... the end"
function signature
(format-multiline (format-string &rest args))
Format n
to have thousand separators.
For example:
(format-thousands-separators 3032498000)
;; => "3,032,498,000"
function signature
(format-thousands-separators (n))
Fraction denominator
of circle to radians.
function signature
(fraction-radian (denominator))
Generate a name with pattern untitled-n.
function signature
(generate-untitled-name)
Get the current display resolution in OSX.
Uses the mac system_profiler SPDisplaysDataType
to lookup the
current display resolution. This is then filtered out (using grep
& perl) and formattted to a list of (w h)
.
For example:
(get-osx-display-resolution)
;; => ("3840" "2160")
function signature
(get-osx-display-resolution)
Get the position of nearest s
.
optional arg
when less than zero, default to the before match
when matches are equidistant from the current point.
function signature
(get-position-of-nearest-matching (s &optional arg))
Get the position of nearest regexp
match.
optional arg
when less than zero, default to the before match
when matches are equidistant from the current point.
function signature
(get-position-of-nearest-regexp-match (regexp &optional arg))
Use git ls-files to open changed files.
function signature
(git-open-changed-and-new-files)
Use git ls-files to open changed files.
function signature
(git-open-changed-files)
Use git-ls-options
to open changed files.
function signature
(git-open-from-ls-files (git-ls-options))
Use git-ls-options
to open changed files.
function signature
(git-open-ls-files (git-ls-options))
Use git ls-files to open untracked files.
Open any untracked file in the repo (unless it's been .gitignored)
function signature
(git-open-untracked-files)
Browse a github repo
by supplying the user/reponame.
function signature
(github-browse-repo (repo))
Translate text
from English to Thai.
function signature
(google-en-to-thai (text))
Translate english in region (begin
end
) to Thai.
function signature
(google-en-to-thai-on-region (begin end))
Convert hex num
to decimal.
function signature
(hex-to-decimal (num))
Adjust the default font :height by 10, universal argument is m
(to set by multiples).
function signature
(increase-default-font-height (m))
Increment number at point like vim's Ctrl a.
function signature
(increment-number-at-point)
Increment the number forward from point by arg
.
function signature
(increment-number-binary (&optional arg))
Indent the current buffer.
function signature
(indent-buffer)
Insert the base filename for the current buffer.
If your're in the minibuffer it will use the other buffer file name.
function signature
(insert-buffer-base-filename)
Insert the filename for the current buffer.
If your're in the minibuffer it will use the other buffer file name.
function signature
(insert-buffer-filename)
Insert date
.
function signature
(insert-iso8601-date (&optional date))
Insert string
and copy to the kill ring.
function signature
(insert-kill (string))
Insert a random number within the range of start
and end
.
function signature
(insert-random-in-range (start end))
Insert a radian value from 0 to 6.28318 (2PI : 360 deg).
function signature
(insert-random-radian)
Insert a random item from a list of strings
.
function signature
(insert-sample (strings))
Insert current time.
function signature
(insert-time-now)
convert an integer into it's binary representation in string format
function signature
(int-to-binary-string (i))
Is the filename
markdown.
function signature
(is-markdown-filename-p (filename))
Join line from below.
function signature
(join-line-from-below)
Join this line or the lines in the selected region.
function signature
(join-line-or-lines-in-region)
Kill untitled buffers.
function signature
(kill-untitled-buffers)
Kill the current word at point.
function signature
(kill-whole-word)
Get a list of macOS windowids.
function signature
(macos-get-list-of-windowids)
Get the windowid of app
.
function signature
(macos-get-window-id-of (app))
Get the windowid of app
.
function signature
(macos-get-window-id-of-app (app))
Just git commit --amend.
function signature
(magit-just-amend)
Make a 24bit color table using Kurecolor.
function signature
(make-kurecolor-24bit-hue-table (color))
Make a hue table from hex color at top of kill ring, no error checking.
function signature
(make-kurecolor-hue-table)
Make a yasnippet from the current region begin
end
.
You should use standard snippet formatting in place, e.g.
You'll be prompted for a name, trigger key and when prefix-arg
is
specified, a snippet group.
function signature
(make-yas-from-region (begin end))
Arrange windows for markdown-soma-start
.
Internally uses the script ~/.doom.d/bin/emacs-markdown-preview-layout.osa
.
function signature
(markdown-soma-window-arrangement-start)
Arrange windows for markdown-soma-stop
.
Internally uses the script ~/.doom.d/bin/emacs-markdown-preview-close.osa
.
function signature
(markdown-soma-window-arrangement-stop)
Switch from cua rectangle to multiple cursors.
function signature
(mc/cua-rectangle-to-multiple-cursors)
Replace markdown inline code with docstring arg style in string
.
For example:
(md-code-to-docstring-arg "`code`")
;; => CODE
function signature
(md-code-to-docstring-arg (string))
Incremental search through open buffers.
function signature
(my-isearch-buffers)
Show all lines matching regexp
in all buffers.
Optionally check allbufs
.
function signature
(my-multi-occur-in-matching-buffers (regexp &optional allbufs))
Open a new buffer called untitled-n.
function signature
(new-untitled-buffer)
Kill all buffers, leaving scratch only.
function signature
(nuke-all-buffers)
Kill all the open buffers except the current one. Leave scratch and Messages alone too.
function signature
(nuke-all-buffers-execept-current)
Prepare collated binding LIST for documentation.
function signature
(ocodo-clean-key-bindings-for-documentation (binding-list))
Collate all key bindings found in ocodo-key-bindings-lisp-files.
function signature
(ocodo-collate-key-bindings-for-documentation)
Generate markdown file
with table of custom bindings
function signature
(ocodo-custom-key-bindings-markdown (file))
Filter bindings
by filter
on index
.
function signature
(ocodo-filter-key-bindings (filter index bindings))
Convert binding-groups
to string of markdown tables.
function signature
(ocodo-key-binding-groups-to-markdown (binding-groups headings))
Cleaned list of key bindings for documentation.
function signature
(ocodo-key-bindings-for-documentation)
key-binding
string directions to unicode arrows.
replaced with ↑ ↓ ← →.
replaced with ⮐.
Setting white-arrows
to t, gives these replacements: ⇧ ⇩ ⇦ ⇨ and ⏎.
function signature
(ocodo-key-bindings-use-unicode-symbols (key-binding &optional white-arrows))
Collect bindings
and headings
into groups
.
function signature
(ocodo-make-key-binding-groups (bindings headings groups))
Make a table row from binding
.
function signature
(ocodo-make-key-binding-table-row (binding))
Set up shell script indenation rules engines.
function signature
(ocodo-sh-indent-rules)
Collect bindings
and HEADINGS into groups
.
function signature
(ocodo-ungrouped-key-bindings (bindings title groups))
Open a newline above the current point, without moving.
function signature
(open-line-above)
Open a newline below the current point, without moving.
function signature
(open-line-below)
Open the current file in intellij IDEA (OS X specific).
function signature
(open-this-in-intellij-idea-osx)
Open the current file in XCode.
function signature
(open-this-in-xcode)
Read the commentary from current emacslisp file and write it to markdown-file
.
Conversion is minimal and expects that most of the docstring is already formatted as
markdown. Quoted items
will be converted to backquoted items
.
function signature
(package-commentary-to-markdown (markdown-file &optional emacslisp-file))
Insert the ELPA package file ending string.
(When it's missing)
function signature
(package-insert-ends-here)
Read markdown-file
and insert it into the emacslisp-file
commentary.
Conversion is minimal and assumes the the markdown is suitable for insertion as
commentary. Backquoted code
will be converted to Emacs quoted items
.
function signature
(package-markdown-to-commentary (markdown-file &optional emacslisp-file))
Insert a pcre regexp to match a list of words
.
function signature
(pcre-regexp-from-list-of-words (words))
Return a random number in range start
to end
.
function signature
(random-in-range (start end))
Run a simple applescript to reload the current Google Chrome tab.
OSX specific.
function signature
(reload-current-chrome-tab-osx)
Run a simple applescript to reload the current Google Chrome tab.
OSX specific.
function signature
(reload-current-firefox-tab-osx)
Renames current buffer and file it is visiting.
function signature
(rename-this-buffer-and-file)
Replace pretty quotes with standard quotes.
function signature
(replace-pretty-quotes)
Replace regexp from
to to
and return cursor to point.
function signature
(replace-regexp-and-return (from to))
No docstring available: TODO
function signature
(replace-region-with (fn))
Get the current thing at point.
Replace with the return value of the function fn
function signature
(replace-thing-at-point-with (fn))
Revert buffer without prompting.
function signature
(revert-buffer-instant)
Squeeze the occurences of char
in string
.
This works the same as tr -s
char``.
function signature
(s-squeeze (char string))
Find a hex color, and replace it with a newly created variable name. Place the created variable at the top of the file. Name it based on the property being set, and its CSS selector, and set its css-value to the hex color found.
function signature
(sass-hex-color-to-var)
Screencapture on macOS, interactive or supply commandline
and FILE_KEYWORD.
function signature
(screencapture-mac (&optional commandline file-keyword))
Do completeing read for arguments of option.
function signature
(screencapture-mac--complete-arguments-for-option (plist))
No docstring available: TODO
function signature
(screencapture-mac--entry-from-summaries (summaries))
Generate a filename for the screenshot at path
with optional ext
and FILE_KEYWORD.
function signature
(screencapture-mac--filename-generator (path &optional ext file-keyword))
Fetch the option from summary
function signature
(screencapture-mac--get-option (summary))
Command line options for screencapture (macOS).
function signature
(screencapture-mac--options)
No docstring available: TODO
function signature
(screencapture-mac--options-summary (plist))
Execute the shell command
with filename
.
function signature
(screencapture-mac--run (command filename))
Summarized list of screencapture mac options
function signature
(screencapture-mac--summary-list)
Get the windowid from a completing-read list.
function signature
(screencapture-mac--windowid-helper)
Reset the default commandline
function signature
(screencapture-mac-reset-default-commandline)
Search for a string backwards from the current point.
Use the strings wrap_start
and wrap_end
, to match the start and
end of the string.
if wrap_end
and wrap_start
are equal, we first position the point
at the beginning of the first wrap_end
match, before the initial
point.
The string found between the two wrappers is returned.
This is useful for naive finding of symbols previously defined in the buffer.
function signature
(search-backward-wrapped-string (wrap_start wrap_end))
Search to the nearest hex color.
Use negative prefix p
to go backward.
function signature
(search-for-nearest-hex-color (p))
Set the default font :height p
(prefix arg) or enter in minibuffer.
function signature
(set-default-font-height (p))
Set or reset the internal border width n
of the selected frame.
function signature
(set-internal-border (n))
Run a shell command, using the file of current buffer as input. Return an error if no buffer file.
function signature
(shell-command-on-buffer-file)
Run shell-command-on-region
replacing the selected region. start
end
command
.
function signature
(shell-command-on-region-replace (start end command))
Move point to first non-whitespace character or beginning-of-line
.
function signature
(smart-beginning-of-line)
Insert a snip line - - 8< - - -
comment.
function signature
(snippy-comment)
Sort sexps in region. Comments stay with the code below.
function signature
(sort-sexps (beg end))
Ensure $SSH_AUTH_SOCK is set correctly in the environment.
function signature
(ssh-agent-env-fix)
Switch to the message buffer.
function signature
(switch-to-message-buffer)
Switch to minibuffer window (if active).
function signature
(switch-to-minibuffer-window)
Switch to scratch, grab the region if it's active.
function signature
(switch-to-scratch)
current time.
function signature
(time-now)
Convert time
hh:mm:ss
into seconds.
function signature
(time-to-seconds (time))
Toggle the current window split.
function signature
(toggle-window-split)
Untabify the current buffer.
function signature
(untabify-buffer)
Insert UTC seconds.
function signature
(utc-seconds)