summaryrefslogtreecommitdiff
path: root/text-conf.el
diff options
context:
space:
mode:
Diffstat (limited to 'text-conf.el')
-rw-r--r--text-conf.el36
1 files changed, 36 insertions, 0 deletions
diff --git a/text-conf.el b/text-conf.el
index a035593..bbd49e9 100644
--- a/text-conf.el
+++ b/text-conf.el
@@ -1,6 +1,7 @@
;;; text-conf.el --- My configurations about plain text files. -*- lexical-binding: t; -*-
(require 'text-mode)
+(require 'rx)
;; (declare-function #'center-buffer-on "center-buffer" nil)
;; (declare-function #'center-buffer-off "center-buffer" nil)
@@ -47,6 +48,39 @@ exactly the current ilne."
(insert remainder-string))))
;;;###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))
+ (let ((len 0))
+ (mapc (lambda (char)
+ (let ((name (get-char-code-property char 'name))
+ (decomposition (get-char-code-property char 'decomposition)))
+ (cond
+ ((or (and
+ (stringp name)
+ (string-match (rx-to-string '(seq bos "CJK"))
+ name))
+ (eq (car decomposition) 'wide))
+ (setq len (+ len 1.7)))
+ ((setq len (1+ len))))))
+ str)
+ (floor len)))
+
+;;;###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)))
+ (cond
+ ((> len width)
+ (error "String %s longer than %d" str width))
+ (t (format "%s%s"
+ (make-string (round (- width len) 2)
+ 32)
+ str)))))
+
+;;;###autoload
(defvar make-block-history nil
"The history of block quote descriptions.")
@@ -126,6 +160,8 @@ If ARG is non-nil, use a more verbose format."
;; a diff-dwim
+(autoload 'vc-diff "vc.el")
+
;;;###autoload
(defun durand-diff-dwim (&optional arg)
"Run `diff-buffer-with-file' or `vc-diff'."