From 168bcf9c5804532f4017ccca4d83200cedb7c6b3 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 17 Dec 2015 00:58:26 +0100 Subject: Move editing functions to separate library --- emacs/.emacs.d/site-lisp/oni-editing.el | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 emacs/.emacs.d/site-lisp/oni-editing.el (limited to 'emacs/.emacs.d/site-lisp/oni-editing.el') diff --git a/emacs/.emacs.d/site-lisp/oni-editing.el b/emacs/.emacs.d/site-lisp/oni-editing.el new file mode 100644 index 0000000..ff8a155 --- /dev/null +++ b/emacs/.emacs.d/site-lisp/oni-editing.el @@ -0,0 +1,66 @@ +;;; oni-editing.el --- General editing commands and functions -*- lexical-binding: t; -*- + +;; Copyright (C) 2015 Tom Willemse + +;; Author: Tom Willemse +;; Keywords: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Here are some general editing functions and commands. + +;;; Code: + +(defun oni:change-number-at-point (change-func) + "Use CHANGE-FUNC to change the number at `point'." + (let ((num (number-to-string (funcall change-func (number-at-point)))) + (bounds (bounds-of-thing-at-point 'word))) + (save-excursion + (delete-region (car bounds) (cdr bounds)) + (insert num)))) + +(defun oni:change-prev-case (num dir) + "Change the case of the region or previous word." + (let ((regfunc (if (eq dir 'up) 'upcase-region 'downcase-region)) + (wordfunc (if (eq dir 'up) 'upcase-word 'downcase-word))) + (if (> num 1) + (funcall regfunc (point) (- (point) num)) + (funcall wordfunc -1)))) + +;;;###autoload +(defun oni:decrease-number-at-point () + "Take the number at `point' and replace it with it decreased by 1." + (interactive) + (oni:change-number-at-point #'1-)) + +;;;###autoload +(defun oni:downcase-prev (num) + (interactive "p") + (oni:change-prev-case num 'down)) + +;;;###autoload +(defun oni:increase-number-at-point () + "Take the number at `point' and replace it with it increased by 1." + (interactive) + (oni:change-number-at-point #'1+)) + +;;;###autoload +(defun oni:upcase-prev (num) + (interactive "p") + (oni:change-prev-case num 'up)) + +(provide 'oni-editing) +;;; oni-editing.el ends here -- cgit v1.2.3-54-g00ecf