]> code.delx.au - gnu-emacs-elpa/commitdiff
[aa2u] New command: aa2u-mark-as-text
authorThien-Thi Nguyen <ttn@gnu.org>
Wed, 21 May 2014 10:13:56 +0000 (12:13 +0200)
committerThien-Thi Nguyen <ttn@gnu.org>
Wed, 21 May 2014 10:13:56 +0000 (12:13 +0200)
* packages/ascii-art-to-unicode/ascii-art-to-unicode.el
(aa2u--text-p): New defsubst.
(aa2u-phase-1, aa2u-phase-2): If the character
in question is ‘aa2u--text-p’, just ignore it.
(aa2u-mark-as-text): New command, w/ autoload cookie.

packages/ascii-art-to-unicode/HACKING
packages/ascii-art-to-unicode/NEWS
packages/ascii-art-to-unicode/ascii-art-to-unicode.el

index f591a581d02cd4f178ddc2b5b21cab6d54a20f47..59ba535fc7a5747e81b47a5882d1355a0664a374 100644 (file)
@@ -3,7 +3,6 @@ HACKING ascii-art-to-unicode.el                            -*- org -*-
 This file is both a guide for newcomers and a todo list for oldstayers.
 
 * ideas / wishlist
-*** add phase 0, to grok and lock label (as opposed to line) text
 *** add interactive mode, to choose per-line light vs heavy
 *** improve neighbor-determining heuristic
 *** support "naked" line terminal (no plus)
index 9280cfbc6e75af30bec8025febeb333ca8bd85e3..492c4cad67eb6bd98e60ec9e8a6733e28acea35b 100644 (file)
@@ -2,6 +2,9 @@ NEWS for ascii-art-to-unicode.el
 See the end for copying conditions.
 
 
+- 1.8 | NOT YET RELEASED
+  - new command: ‘aa2u-mark-as-text’
+
 - 1.7 | 2014-05-11
   - new var: ‘aa2u-uniform-weight’
   - new command: ‘aa2u-rectangle’
index 733413c202232808f427c53a4ff034e7267cc349..45e5d0f6f142ed57f844a841b7551467ec8819dd 100644 (file)
 ;;           ┃          ┃
 ;;           ┗━━━━━━━━━━┛
 ;;
+;; To protect particular ‘|’, ‘-’ or ‘+’ characters from conversion,
+;; you can set the property `aa2u-text' on that text with command
+;; `aa2u-mark-as-text'.  A prefix arg clears the property, instead.
+;; (You can use `describe-text-properties' to check.)  For example:
+;;
+;;
+;;      ┌───────────────────┐
+;;      │                   │
+;;      │ |\/|              │
+;;      │ `Oo'   --Oop Ack! │
+;;      │  ^&-MM.           │
+;;      │                   │
+;;      └─────────┬─────────┘
+;;                │
+;;            """""""""
+;;
 ;;
 ;; See Also
 ;; - HACKING: <http://git.sv.gnu.org/cgit/emacs/elpa.git/tree/packages/ascii-art-to-unicode/HACKING>
@@ -93,6 +109,9 @@ This specifies the weight of all the lines.")
 ;;;---------------------------------------------------------------------------
 ;;; support
 
+(defsubst aa2u--text-p (pos)
+  (get-text-property pos 'aa2u-text))
+
 (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 the weight
@@ -136,7 +155,8 @@ Their values are STRINGIFIER and COMPONENTS, respectively."
             (goto-char (point-min))
             (let ((now (aa2u-1c 'aa2u-ucs-bd-uniform-name name)))
               (while (search-forward was nil t)
-                (replace-match now t t)))))
+                (unless (aa2u--text-p (match-beginning 0))
+                  (replace-match now t t))))))
     (gsr "|" 'VERTICAL)
     (gsr "-" 'HORIZONTAL)))
 
@@ -194,9 +214,10 @@ Their values are STRINGIFIER and COMPONENTS, respectively."
     ;; ‘memq’ to an ‘intersction’.
     (while (search-forward "+" nil t)
       (let ((p (point)))
-        (push (cons p (or (aa2u-replacement (1- p))
-                          "?"))
-              changes)))
+        (unless (aa2u--text-p (1- p))
+          (push (cons p (or (aa2u-replacement (1- p))
+                            "?"))
+                changes))))
     ;; (phase 2.2 -- apply changes)
     (dolist (ch changes)
       (goto-char (car ch))
@@ -274,6 +295,19 @@ are START (top left) and END (bottom right)."
     (goto-char (min start end))
     (insert-rectangle now)))
 
+;;;###autoload
+(defun aa2u-mark-as-text (start end &optional unmark)
+  "Set property `aa2u-text' of the text from START to END.
+This prevents `aa2u' from misinterpreting \"|\", \"-\" and \"+\"
+in that region as lines and intersections to be replaced.
+Prefix arg means to remove property `aa2u-text', instead."
+  (interactive "r\nP")
+  (funcall (if unmark
+               'remove-text-properties
+             'add-text-properties)
+           start end
+           '(aa2u-text t)))
+
 ;;;---------------------------------------------------------------------------
 ;;; that's it