split off reg-manipulation

This commit is contained in:
Jean-Philippe Bernardy 2015-10-16 14:29:28 +02:00
parent 17a37e7a1b
commit 4fda3ee2de
2 changed files with 30 additions and 15 deletions

View file

@ -8,6 +8,7 @@
;;; Code:
(require 'boon-core)
(require 'boon-regs)
(defcustom boon-enclosures
'(
@ -92,21 +93,6 @@
(boon-jump-over-blanks)
(point)))))
(defun boon-normalize-reg (reg)
"Normalize the region REG by making sure beginning < end."
(cons (min (cdr reg) (car reg)) (max (cdr reg) (car reg))))
(defun boon-reg-to-markers (reg)
(cons (copy-marker (car reg)) (copy-marker (cdr reg))))
(defun boon-borders (reg how-much)
"Given a normalized region REG, return its borders, whose size is HOW-MUCH."
(list (cons (cdr reg) (- (cdr reg) how-much))
(cons (car reg) (+ (car reg) how-much))))
(defun boon-content (reg)
"Given a normalized region REG, return its contents (crop the region by 1)."
(cons (+ (car reg) 1) (- (cdr reg) 1)))
(defun boon-select-borders (how-much regs)
"Return the bordering (of size HOW-MUCH) of a region list REGS.
@ -128,6 +114,7 @@ This function is meant to be called interactively."
"all regions defined by multiple-cursors-mode, and outside."
(cons (cons (mark) (point))
(if (boon-bypass-mc)
;; TODO: is marker-position really necessary here?
(mapcar (lambda (o) (cons (marker-position (overlay-get o 'mark)) (marker-position (overlay-get o 'point))))
(mc/all-fake-cursors))
nil)))

28
boon-regs.el Normal file
View file

@ -0,0 +1,28 @@
;;; boon --- An Ergonomic Command Mode -*- lexical-binding: t -*-
;;; Commentary:
;; A region list has the following form: ('region (begining . end) (begining . end) ...)
;;; Code:
(defun boon-normalize-reg (reg)
"Normalize the region REG by making sure beginning < end."
(cons (min (cdr reg) (car reg)) (max (cdr reg) (car reg))))
(defun boon-reg-to-markers (reg)
"Put copy the markers defining REG borders, and return that."
(cons (copy-marker (car reg)) (copy-marker (cdr reg))))
(defun boon-borders (reg how-much)
"Given a normalized region REG, return its borders, whose size is HOW-MUCH."
(list (cons (cdr reg) (- (cdr reg) how-much))
(cons (car reg) (+ (car reg) how-much))))
(defun boon-content (reg)
"Given a normalized region REG, return its contents (crop the region by 1)."
(cons (+ (car reg) 1) (- (cdr reg) 1)))
(provide 'boon-regs)
;;; boon-regs.el ends here