]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/ascii-art-to-unicode/ascii-art-to-unicode.el
[aa2u maint] Add ‘Maintainer’ header per top-level README; nfc.
[gnu-emacs-elpa] / packages / ascii-art-to-unicode / ascii-art-to-unicode.el
index 3ebe951c65a6210f92cf1beb32e9eb342d56fc31..e6b1fca931671d9b8df16c2379faddeb128b3c53 100644 (file)
@@ -3,7 +3,8 @@
 ;; Copyright (C) 2014  Free Software Foundation, Inc.
 
 ;; Author: Thien-Thi Nguyen <ttn@gnu.org>
-;; Version: 1.6
+;; Maintainer: Thien-Thi Nguyen <ttn@gnu.org>
+;; Version: 1.7
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -22,6 +23,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
 ;;
 ;; Much easier on the eyes now!
 ;;
+;; Normally, lines are drawn with the `LIGHT' weight.  If you set var
+;; `aa2u-uniform-weight' to symbol `HEAVY', you will see, instead:
+;;
+;;   ┏━━━━━━━━━━━━━━━┓
+;;   ┃               ┃
+;;   ┃       ┏━━━━━━━╋━━┓
+;;   ┃       ┃       ┃  ┃
+;;   ┃       ┃       ┃  ┃
+;;   ┃       ┃       ┃  ┃
+;;   ┗━━━━━━━╋━━━━━━━┛  ┃
+;;           ┃          ┃
+;;           ┃          ┃
+;;           ┃          ┃
+;;           ┗━━━━━━━━━━┛
+;;
 ;;
 ;; See Also
 ;; - HACKING: <http://git.sv.gnu.org/cgit/emacs/elpa.git/tree/packages/ascii-art-to-unicode/HACKING>
 (require 'cl-lib)
 (require 'pcase)
 
+(defvar aa2u-uniform-weight 'LIGHT
+  "A symbol, either `LIGHT' or `HEAVY'.
+This specifies the weight of all the lines.")
+
 ;;;---------------------------------------------------------------------------
 ;;; support
 
-(defun aa2u-ucs-bd-uniform-name (weight &rest components)
+(defun aa2u-ucs-bd-uniform-name (&rest components)
   "Return a string naming UCS char w/ WEIGHT and COMPONENTS.
-The string begins with \"BOX DRAWINGS\"; followed by WEIGHT,
-a symbol from the set:
-
-  HEAVY
-  LIGHT
-
-followed by COMPONENTS, a list of one or two symbols from the set:
+The string begins with \"BOX DRAWINGS\"; followed by the weight
+as per variable `aa2u-uniform-weight', followed by COMPONENTS,
+a list of one or two symbols from the set:
 
   VERTICAL
   HORIZONTAL
@@ -94,7 +111,7 @@ string includes \"AND\" between the elements of COMPONENTS.
 
 Lastly, all words are separated by space (U+20)."
   (format "BOX DRAWINGS %s %s"
-          weight
+          aa2u-uniform-weight
           (mapconcat 'symbol-name components
                      " AND ")))
 
@@ -114,11 +131,11 @@ Their values are STRINGIFIER and COMPONENTS, respectively."
 
 (defun aa2u-phase-1 ()
   (goto-char (point-min))
-  (let ((vert (aa2u-1c 'aa2u-ucs-bd-uniform-name 'LIGHT 'VERTICAL)))
+  (let ((vert (aa2u-1c 'aa2u-ucs-bd-uniform-name 'VERTICAL)))
     (while (search-forward "|" nil t)
       (replace-match vert t t)))
   (goto-char (point-min))
-  (let ((horz (aa2u-1c 'aa2u-ucs-bd-uniform-name 'LIGHT 'HORIZONTAL)))
+  (let ((horz (aa2u-1c 'aa2u-ucs-bd-uniform-name 'HORIZONTAL)))
     (while (search-forward "-" nil t)
       (replace-match horz t t))))
 
@@ -136,7 +153,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)))
@@ -155,7 +172,6 @@ Their values are STRINGIFIER and COMPONENTS, respectively."
          (just (&rest args) (delq nil args)))
       (apply 'aa2u-1c
              'aa2u-ucs-bd-uniform-name
-             'LIGHT
              (just (pcase (just (v 'UP   0)
                                 (v 'DOWN 2))
                      ((pred two-p) 'VERTICAL)
@@ -192,7 +208,7 @@ Their values are STRINGIFIER and COMPONENTS, respectively."
                                 'aa2u-components nil)))
 
 ;;;---------------------------------------------------------------------------
-;;; command
+;;; commands
 
 ;;;###autoload
 (defun aa2u (beg end &optional interactive)
@@ -221,6 +237,9 @@ More precisely, hyphen and vertical bar are substituted unconditionally,
 first, and plus is substituted with a character depending on its north,
 south, east and west neighbors.
 
+NB: Actually, `aa2u' can also use \"HEAVY\" instead of \"LIGHT\",
+depending on the value of variable `aa2u-uniform-weight'.
+
 This command operates on either the active region,
 or the accessible portion otherwise."
   (interactive "r\np")
@@ -240,6 +259,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