Move utility functions from configuration.org to lisp/gpolonkai/utilities.el
This commit is contained in:
@@ -2,105 +2,6 @@
|
||||
|
||||
This is a collection of functions and commands i wrote or stole from all around the internet.
|
||||
|
||||
** Utilities
|
||||
|
||||
*** Make a backup filename under ~user-emacs-cache-directory~
|
||||
|
||||
Taken from [[http://ergoemacs.org/emacs/emacs_set_backup_into_a_directory.html][Xah’s site]].
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun xah/backup-file-name (fpath)
|
||||
"Return a new file path for FPATH under `user-emacs-cache-directory'"
|
||||
(let* ((backup-root-dir (expand-file-name "backup" user-emacs-cache-directory))
|
||||
(file-path (replace-regexp-in-string "[A-Za-z]:" "" fpath))
|
||||
(backup-file-path (replace-regexp-in-string "//" "/" (concat backup-root-dir file-path "~"))))
|
||||
(make-directory (file-name-directory backup-file-path) (file-name-directory backup-file-path))
|
||||
backup-file-path))
|
||||
#+end_src
|
||||
|
||||
*** Check if we’re running under Termux
|
||||
|
||||
We need to do things differently, if so.
|
||||
|
||||
There’s probably a better way, though, other than checking the path of our home directory.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun gpolonkai/termux-p ()
|
||||
"Check if Emacs is running under Termux."
|
||||
(string-match-p
|
||||
(regexp-quote "/com.termux/")
|
||||
(expand-file-name "~")))
|
||||
#+end_src
|
||||
|
||||
*** Find the first number on line
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun gpolonkai/find-number-on-line ()
|
||||
"Find the first number on the current line."
|
||||
(save-excursion
|
||||
(without-restriction
|
||||
(goto-char (pos-bol))
|
||||
(when (re-search-forward "[0-9]+" (pos-eol) t)
|
||||
(number-at-point)))))
|
||||
#+end_src
|
||||
|
||||
*** Round number at point to the given decimals
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun gpolonkai/round-number-at-point-to-decimals (decimal-count)
|
||||
(interactive "NDecimal count: ")
|
||||
(let ((mult (expt 10 decimal-count)))
|
||||
(replace-match (number-to-string
|
||||
(/
|
||||
(fround
|
||||
(*
|
||||
mult
|
||||
(number-at-point)))
|
||||
mult)))))
|
||||
#+end_src
|
||||
|
||||
*** Leave ~isearch~ at the other end of the matched string
|
||||
|
||||
From [[http://endlessparentheses.com/leave-the-cursor-at-start-of-match-after-isearch.html][Endless Parentheses]].
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun ep/isearch-exit-other-end ()
|
||||
"Exit isearch, at the opposite end of the string."
|
||||
(interactive)
|
||||
|
||||
(isearch-exit)
|
||||
(goto-char isearch-other-end))
|
||||
#+end_src
|
||||
|
||||
*** Mark the current match after leaving ~isearch~
|
||||
|
||||
From [[http://emacs.stackexchange.com/a/31321/507][Emacs SE]].
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun e-se/isearch-exit-mark-match ()
|
||||
"Exit isearch and mark the current match."
|
||||
(interactive)
|
||||
(isearch-exit)
|
||||
(push-mark isearch-other-end)
|
||||
(activate-mark))
|
||||
#+end_src
|
||||
|
||||
*** Copy the prototype of the current C function
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun gpolonkai/copy-func-prototype ()
|
||||
"Copy the current function's prototype to the kill ring."
|
||||
|
||||
(interactive)
|
||||
|
||||
(save-excursion
|
||||
(beginning-of-defun)
|
||||
(let ((protocopy-begin (point)))
|
||||
(forward-list)
|
||||
(let ((protocopy-end (point)))
|
||||
(kill-ring-save protocopy-begin protocopy-end)))))
|
||||
#+end_src
|
||||
|
||||
** Window manipulation
|
||||
|
||||
*** Bury a window
|
||||
|
Reference in New Issue
Block a user