summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-08-04 11:15:05 +0800
committerJSDurand <mmemmew@gmail.com>2021-08-04 11:15:05 +0800
commitab6dec9dfd1c38ca1b6df0175a0c71f11fc8af9e (patch)
tree408641fe42b9d6b672e9001d5cc7b5b12b6b3402
parent9e0e6c886140e8845b187d83e57abc3dd4489d32 (diff)
fix: make text-conf stand alone
* text-conf.el (correct-length): Was using a function from modeline configurations. I might want to revert back to that function in the future. (center-string-in-width): Was using a function from my novel-reading package. (vc-diff): Add an autoload.
-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'."