2015-12-17 00:58:26 +01:00
|
|
|
;;; oni-editing.el --- General editing commands and functions -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;; Copyright (C) 2015 Tom Willemse
|
|
|
|
|
|
|
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
|
|
|
;; 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; Here are some general editing functions and commands.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2015-12-18 00:13:16 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun oni:move-beginning-of-dwim ()
|
|
|
|
"Move to beginning of line either after indentation or before."
|
|
|
|
(interactive)
|
|
|
|
(let ((start (point)))
|
|
|
|
(back-to-indentation)
|
|
|
|
(if (= start (point))
|
|
|
|
(move-beginning-of-line 1))))
|
|
|
|
|
2015-12-17 00:58:26 +01:00
|
|
|
(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))
|
|
|
|
|
2015-12-18 00:13:16 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun oni:move-end-of-dwim ()
|
|
|
|
"Move to end of line, either before any comments or after."
|
|
|
|
(interactive)
|
|
|
|
(let ((start (point))
|
|
|
|
(eolpos (line-end-position)))
|
|
|
|
(beginning-of-line)
|
|
|
|
(if (and comment-start
|
|
|
|
(not (looking-at (regexp-quote comment-start)))
|
|
|
|
(comment-search-forward eolpos t))
|
|
|
|
(progn
|
|
|
|
(search-backward-regexp (concat "[^ \t" comment-start "]"))
|
|
|
|
(forward-char)
|
|
|
|
|
|
|
|
(when (or (bolp)
|
|
|
|
(= start (point)))
|
|
|
|
(end-of-line)))
|
|
|
|
(end-of-line))))
|
|
|
|
|
2015-12-17 00:58:26 +01:00
|
|
|
;;;###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+))
|
|
|
|
|
2015-12-17 01:15:30 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun oni:indent-defun ()
|
|
|
|
"Indent the current defun."
|
|
|
|
(interactive)
|
|
|
|
(save-excursion
|
|
|
|
(mark-defun)
|
|
|
|
(indent-region (region-beginning) (region-end))))
|
|
|
|
|
2015-12-17 01:27:39 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun oni:locally-enable-double-spaces ()
|
|
|
|
"Specify that two spaces end a sentence in the current buffer."
|
|
|
|
(setq-local sentence-end-double-space t))
|
|
|
|
|
2015-12-18 01:17:59 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun oni:reload-buffer ()
|
|
|
|
"Reload current buffer."
|
|
|
|
(interactive)
|
|
|
|
(revert-buffer nil t nil))
|
|
|
|
|
2015-12-17 00:58:26 +01:00
|
|
|
;;;###autoload
|
|
|
|
(defun oni:upcase-prev (num)
|
|
|
|
(interactive "p")
|
|
|
|
(oni:change-prev-case num 'up))
|
|
|
|
|
|
|
|
(provide 'oni-editing)
|
|
|
|
;;; oni-editing.el ends here
|