summaryrefslogtreecommitdiff
path: root/text-conf.el
diff options
context:
space:
mode:
Diffstat (limited to 'text-conf.el')
-rw-r--r--text-conf.el89
1 files changed, 89 insertions, 0 deletions
diff --git a/text-conf.el b/text-conf.el
new file mode 100644
index 0000000..1fe9696
--- /dev/null
+++ b/text-conf.el
@@ -0,0 +1,89 @@
+;;; text-conf.el --- My configurations about plain text files. -*- lexical-binding: t; -*-
+
+(require 'text-mode)
+
+;;;###autoload
+(defvar insert-section-heading-history nil
+ "The history of inserted section heading strings")
+
+;;;###autoload
+(defun insert-section-heading (custom-heading)
+ "Insert a heading line below.
+
+If CUSTOM-HEADING is non-nil, then use a custom heading.
+
+The user can input any string as a basic constituent of a
+heading. The inputed string will be repeated (floor N M) times,
+where N is the length of the current line and M is the lenght of
+the input string. After this repeat the first (remainder N M)
+characters of the input string will be inserted as well to cover
+exactly the current ilne."
+ (interactive "P")
+ (let* ((current-length (- (point-at-eol)
+ (point-at-bol)))
+ (heading (cond
+ ((null custom-heading) "-")
+ (t (read-string "Enter a custom heading: "
+ nil insert-section-heading-history
+ "-" t))))
+ (floor-length (floor current-length (length heading)))
+ (remainder (% current-length (length heading)))
+ (remainder-string (substring heading 0 remainder))
+ (index 0))
+ (save-excursion
+ (goto-char (line-end-position))
+ (newline)
+ (while (< index floor-length)
+ (message "index: %s" index)
+ (message "floor: %s" floor-length)
+ (insert heading)
+ (setq index (1+ index)))
+ (insert remainder-string))))
+
+;;;###autoload
+(defvar make-block-history nil
+ "The history of block quote descriptions.")
+
+;;;###autoload
+(defun make-block (&optional description)
+ "Surround the current line or the region in a block.
+
+If DESCRIPTION is non-nil, ask for a description and put the
+DESCRIPTION above the block."
+ (interactive "P")
+ (let* ((beg (cond
+ ((use-region-p)
+ (region-beginning))
+ ((line-beginning-position))))
+ (end (cond
+ ((use-region-p)
+ (region-end))
+ ((line-end-position))))
+ (end-marker (set-marker (make-marker) (1+ end)))
+ (fill-line (make-string fill-column ?=))
+ (header (cond
+ (description
+ (list fill-line
+ "\n"
+ (center-string-in-width
+ (read-string "Description of the block: "
+ nil make-block-history nil t)
+ fill-column)
+ "\n"
+ fill-line))
+ (t (list fill-line)))))
+ (save-excursion
+ (goto-char beg)
+ (while (<= (point) (1- (marker-position end-marker)))
+ (center-line)
+ (forward-line 1))
+ (goto-char beg)
+ (mapc #'insert header)
+ (newline)
+ (goto-char (1- (marker-position end-marker)))
+ (set-marker end-marker nil)
+ (newline)
+ (insert fill-line))))
+
+(provide 'text-conf)
+;;; text-conf.el ends here.