From ab6dec9dfd1c38ca1b6df0175a0c71f11fc8af9e Mon Sep 17 00:00:00 2001 From: JSDurand Date: Wed, 4 Aug 2021 11:15:05 +0800 Subject: 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. --- text-conf.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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) @@ -46,6 +47,39 @@ exactly the current ilne." (setq index (1+ index))) (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'." -- cgit v1.2.3-18-g5258