;;; zzq-funcs.el --- miscellaneous functions ;; Author: jason ;; Created: 15 Jun 2017 ;; X-URL: https://beehive.io/jason/emacs.d/ ;;; Commentary: ;; ;; Contains miscellaneous functions I've written or collected. ;; ;;; Code: (defun zzq/time-to-sec (time) "Convert the output of (current-time) to epoch in seconds" (truncate (+ (+ (* (nth 0 time) (expt 2 16)) (nth 1 time)) (* (nth 2 time) (expt 10 -6))))) (defun zzq/time-to-msec (time) "Convert the output of (current-time) to epoch in milliseconds" (truncate (* 1000 (+ (+ (* (nth 0 time) (expt 2 16)) (nth 1 time)) (* (nth 2 time) (expt 10 -6)))))) (defun kill-whitespace () "Remove all whitepspace seperating two non-whitespace characters" (interactive "*") (save-excursion (save-restriction (progn ;; Move backward to the last non-whitespace character (re-search-backward "[^ \t\r\n]" nil) ;; Then search for all whitespace to the next non-whitespace character (re-search-forward "[ \t\r\n]+") ;; Replace everything from the last match (all whitespace) with nothing (replace-match ""))))) (defun maybe-backward-kill-word (arg) "Removes all whitespace backward up to the next non-whitespace character. If the first character left of the cursor is not whitespace then remove the word. I like to bind this to C-backspace." (interactive "p") (if (looking-back "[ \t\r\n]") (let ((start (point))) (re-search-backward "[^ \t\r\n]" nil) (forward-char 1) (delete-region (point) start)) (backward-kill-word arg))) (defun maybe-kill-word (arg) "Removes all whitespace up to the next non-whitespace character. If the first character right of the cursor is not whitespace then remove the word. I like to bind this to C-delete and M-d" (interactive "p") (if (looking-at "[ \t\r\n]") (let ((start (point))) (re-search-forward "[ \t\r\n]+" nil) (delete-region (point) start)) (kill-word arg))) (provide 'zzq-funcs)