summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThien-Thi Nguyen <ttn@gnu.org>2014-05-21 12:13:56 +0200
committerThien-Thi Nguyen <ttn@gnu.org>2014-05-21 12:13:56 +0200
commitc25476c94d89558083ab6f9cfbeb6c95ab9abb6d (patch)
tree8d53055034f3969bf9a2350cf071182074774257
parentdfc56c74b03b6f2de740e3718b2362e56402f251 (diff)
[aa2u] New command: aa2u-mark-as-text
* 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.
-rw-r--r--HACKING1
-rw-r--r--NEWS3
-rw-r--r--ascii-art-to-unicode.el42
3 files changed, 41 insertions, 5 deletions
diff --git a/HACKING b/HACKING
index f591a58..59ba535 100644
--- a/HACKING
+++ b/HACKING
@@ -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)
diff --git a/NEWS b/NEWS
index 9280cfb..492c4ca 100644
--- a/NEWS
+++ b/NEWS
@@ -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’
diff --git a/ascii-art-to-unicode.el b/ascii-art-to-unicode.el
index 733413c..45e5d0f 100644
--- a/ascii-art-to-unicode.el
+++ b/ascii-art-to-unicode.el
@@ -76,6 +76,22 @@
;; ┃ ┃
;; ┗━━━━━━━━━━┛
;;
+;; 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