summaryrefslogtreecommitdiff
path: root/text-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-12-21 21:35:57 +0800
committerJSDurand <mmemmew@gmail.com>2021-12-21 21:35:57 +0800
commite8dbbb51a261d189e8c486cf6ce90b533e0d479f (patch)
treea8bc4f12b02523062b20c48b950288ed7ba47a83 /text-conf.el
parent5849cd830f00d67483c98f713ae42ba189cf039a (diff)
text-conf: Clean up and new durand-elide-region command
* text-conf.el (correct-length): Obsolete now. (center-string-in-width): Use string-width. (durand-elide-region, text-mode-map): New command to elide a region of texts.
Diffstat (limited to 'text-conf.el')
-rw-r--r--text-conf.el48
1 files changed, 43 insertions, 5 deletions
diff --git a/text-conf.el b/text-conf.el
index bbd49e9..ad0d78f 100644
--- a/text-conf.el
+++ b/text-conf.el
@@ -9,6 +9,8 @@
;; (define-key text-mode-map (vector 'f8) nil)
+;;; Insert section heading
+
;;;###autoload
(defvar insert-section-heading-history nil
"The history of inserted section heading strings")
@@ -47,12 +49,15 @@ exactly the current ilne."
(setq index (1+ index)))
(insert remainder-string))))
+;;; Center text
+
;;;###autoload
(defun correct-length (str)
"Return the length of STR.
Characters that take up more than one column will be counted with
1.7 columns."
- (declare (side-effect-free t) (pure t))
+ (declare (side-effect-free t) (pure t)
+ (obsolete string-width "2021-12-21 20:56:10.928712"))
(let ((len 0))
(mapc (lambda (char)
(let ((name (get-char-code-property char 'name))
@@ -70,8 +75,9 @@ Characters that take up more than one column will be counted with
;;;###autoload
(defun center-string-in-width (str width)
- "Add spaces to STR so that it is centered in a box which is WIDTH wide."
- (let ((len (correct-length str)))
+ "Add spaces to STR so that it is centered in a box which is WIDTH \
+wide."
+ (let ((len (string-width str)))
(cond
((> len width)
(error "String %s longer than %d" str width))
@@ -80,6 +86,8 @@ Characters that take up more than one column will be counted with
32)
str)))))
+;;; Make a block
+
;;;###autoload
(defvar make-block-history nil
"The history of block quote descriptions.")
@@ -125,6 +133,8 @@ DESCRIPTION above the block."
(newline)
(insert fill-line))))
+;;; Moving between pages
+
;;;###autoload
(defun durand-next-page (&optional arg)
"Move forward ARG pages and narrow to page.
@@ -145,7 +155,7 @@ Pass (- (prefix-numeric-value arg)) to `durand-next-page'."
(define-key text-mode-map (vector ?\s-m) #'durand-previous-page)
(define-key text-mode-map (vector ?\s-รน) #'durand-next-page)
-;; Insert time stamps
+;;; Insert time stamps
;;;###autoload
(defun durand-insert-timestamp (&optional arg)
@@ -158,7 +168,7 @@ If ARG is non-nil, use a more verbose format."
(define-key global-map (vector ?\H-=) #'durand-insert-timestamp)
-;; a diff-dwim
+;;; a diff-dwim
(autoload 'vc-diff "vc.el")
@@ -181,5 +191,33 @@ If ARG is non-nil, use a more verbose format."
(define-key global-map (vector ?\C-\M-=) #'durand-diff-dwim)
+;;; Eliding a region of text
+
+(defun durand-elide-region (beg end ignore-invisible-lines)
+ "Elide a region of text delimited by BEG and END.
+If IGNORE-INVISIBLE-LINES is non-nil, the line count will not
+include invisible lines."
+ (interactive
+ (cond
+ ((use-region-p) (list (region-beginning) (region-end)
+ current-prefix-arg))
+ ((user-error "First select a region to elide"))))
+ (cond
+ ((> beg end)
+ (let ((temp beg))
+ (setq beg end) (setq end temp))))
+ (setq beg (save-excursion
+ (goto-char beg)
+ (line-beginning-position)))
+ (setq end (save-excursion
+ (goto-char end)
+ (line-end-position)))
+ (let ((n (count-lines beg end ignore-invisible-lines)))
+ (save-excursion
+ (delete-region beg end)
+ (insert (format " >> [ %d lines elided ... ]" n)))))
+
+(define-key text-mode-map (vector ?\M-\s-\=) #'durand-elide-region)
+
(provide 'text-conf)
;;; text-conf.el ends here.