]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/ascii-art-to-unicode/ascii-art-to-unicode.el
[aa2u] New command: aa2u-rectangle
[gnu-emacs-elpa] / packages / ascii-art-to-unicode / ascii-art-to-unicode.el
index 89bcb928d8aec4df8e7a081d43421135819bef38..ea7ea8609dd557cb05f40ce4f3803213b6edf4ae 100644 (file)
@@ -22,6 +22,7 @@
 
 ;; The command `aa2u' converts simple ASCII art line drawings in
 ;; the {active,accessible} region of the current buffer to Unicode.
+;; Command `aa2u-rectangle' is like `aa2u', but works on rectangles.
 ;;
 ;; Example use case:
 ;; - M-x artist-mode RET
@@ -83,7 +84,7 @@
 (require 'cl-lib)
 (require 'pcase)
 
-(defvar aa2u-uniform-weight 'HEAVY
+(defvar aa2u-uniform-weight 'LIGHT
   "A symbol, either `LIGHT' or `HEAVY'.
 This specifies the weight of all the lines.")
 
@@ -151,7 +152,7 @@ Their values are STRINGIFIER and COMPONENTS, respectively."
                     ;;              |      +---|
                     (eq ?+ (char-after pos))
                     ;; Require properly directional neighborliness.
-                    (memq (case name
+                    (memq (cl-case name
                             ((UP DOWN)    'VERTICAL)
                             ((LEFT RIGHT) 'HORIZONTAL))
                           (get-text-property pos 'aa2u-components)))
@@ -206,7 +207,7 @@ Their values are STRINGIFIER and COMPONENTS, respectively."
                                 'aa2u-components nil)))
 
 ;;;---------------------------------------------------------------------------
-;;; command
+;;; commands
 
 ;;;###autoload
 (defun aa2u (beg end &optional interactive)
@@ -257,6 +258,20 @@ or the accessible portion otherwise."
       (aa2u-phase-2)
       (aa2u-phase-3))))
 
+;;;###autoload
+(defun aa2u-rectangle (start end)
+  "Like `aa2u' on the region-rectangle.
+When called from a program the rectangle's corners
+are START (top left) and END (bottom right)."
+  (interactive "r")
+  (let* ((was (delete-extract-rectangle start end))
+         (now (with-temp-buffer
+                (insert-rectangle was)
+                (aa2u (point) (mark))
+                (extract-rectangle (point-min) (point-max)))))
+    (goto-char (min start end))
+    (insert-rectangle now)))
+
 ;;;---------------------------------------------------------------------------
 ;;; that's it