emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 02/02: [aa2u] New command: aa2u-mark-as-text


From: Thien-Thi Nguyen
Subject: [elpa] 02/02: [aa2u] New command: aa2u-mark-as-text
Date: Wed, 21 May 2014 10:09:22 +0000

ttn pushed a commit to branch master
in repository elpa.

commit aa4afe3bab1ba1f7bb4d1b606ffa9311160c017f
Author: Thien-Thi Nguyen <address@hidden>
Date:   Wed May 21 12:13:56 2014 +0200

    [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.
---
 packages/ascii-art-to-unicode/HACKING              |    1 -
 packages/ascii-art-to-unicode/NEWS                 |    3 +
 .../ascii-art-to-unicode/ascii-art-to-unicode.el   |   42 ++++++++++++++++++--
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/packages/ascii-art-to-unicode/HACKING 
b/packages/ascii-art-to-unicode/HACKING
index f591a58..59ba535 100644
--- a/packages/ascii-art-to-unicode/HACKING
+++ b/packages/ascii-art-to-unicode/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/packages/ascii-art-to-unicode/NEWS 
b/packages/ascii-art-to-unicode/NEWS
index 9280cfb..492c4ca 100644
--- a/packages/ascii-art-to-unicode/NEWS
+++ b/packages/ascii-art-to-unicode/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/packages/ascii-art-to-unicode/ascii-art-to-unicode.el 
b/packages/ascii-art-to-unicode/ascii-art-to-unicode.el
index 733413c..45e5d0f 100644
--- a/packages/ascii-art-to-unicode/ascii-art-to-unicode.el
+++ b/packages/ascii-art-to-unicode/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
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]