<commit_before>;;; ascii-braille.el --- Replace Unicode Braille with Ascii Braille overlays

;; Copyright (C) 2020 <NAME>

;; Author: <NAME> <<EMAIL>>
;; Version: 0.1
;; URL: https://github.com/liblouis/ascii-braille-overlay/
;; Keywords: faces, matching, braille
;; Package-Requires: ((emacs "24.3") (ht "2.2"))

;; 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
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Replace unicode braille with ascii braille overlays while. It was
;; originally inspired by the package `symbol-overlays'.

;; Usage

;; Toggle the `ascii-braille-mode' minor mode to see the unicode
;; braille in your buffer as ascii braille. Disabling the minor will
;; remove all overlays.

;; TODO

;; I suppose it would be nice if you could edit the ascii braille and
;; have it reflected in the unicode braille.

;;; Code:

(require 'ht)

(defconst ascii-braille-unicode-to-ascii-map
  (ht
   (?⠀ ? )
   (?⠁ ?a)
   (?⠃ ?b)
   (?⠉ ?c)
   (?⠙ ?d)
   (?⠑ ?e)
   (?⠋ ?f)
   (?⠛ ?g)
   (?⠓ ?h)
   (?⠊ ?i)
   (?⠚ ?j)
   (?⠅ ?k)
   (?⠇ ?l)
   (?⠍ ?m)
   (?⠝ ?n)
   (?⠕ ?o)
   (?⠏ ?p)
   (?⠟ ?q)
   (?⠗ ?r)
   (?⠎ ?s)
   (?⠞ ?t)
   (?⠥ ?u)
   (?⠧ ?v)
   (?⠺ ?w)
   (?⠭ ?x)
   (?⠽ ?y)
   (?⠵ ?z)
   (?⠬ ?0)
   (?⠡ ?1)
   (?⠣ ?2)
   (?⠩ ?3)
   (?⠹ ?4)
   (?⠱ ?5)
   (?⠫ ?6)
   (?⠻ ?7)
   (?⠳ ?8)
   (?⠪ ?9)
   (?⠯ ?&)
   (?⠿ ?%)
   (?⠷ ?{)
   (?⠮ ?~)
   (?⠾ ?})
   (?⠂ ?,)
   (?⠆ ?\;)
   (?⠒ ?:)
   (?⠲ ?/)
   (?⠢ ??)
   (?⠖ ?+)
   (?⠶ ?=)
   (?⠦ ?()
   (?⠔ ?*)
   (?⠴ ?))
   (?⠄ ?.)
   (?⠤ ?-)
   (?⠌ ?|)
   (?⠜ ?`)
   (?⠼ ?#)
   (?⠈ ?\")
   (?⠐ ?!)
   (?⠘ ?>)
   (?⠨ ?$)
   (?⠸ ?_)
   (?⠰ ?<)
   (?⠠ ?')))

(defgroup ascii-braille nil
  "Convert unicode braille to ascii braille using overlays."
  :group 'convenience)

(defface ascii-braille-overlay-default-face
  '((t (:inherit highlight)))
  "Ascii braille overlay default face"
  :group 'ascii-braille)

(defun ascii-braille-unicode-to-ascii (char)
  "Convert a unicode braille char to ascii braille. If the char
is not a unicode braille char just return the char itself."
  (ht-get ascii-braille-unicode-to-ascii-map char char))

(defun ascii-braille-to-ascii (s)
  "Convert a unicode braille string to a ascii braille string."
  (seq-concatenate 'string (seq-map #'ascii-braille-unicode-to-ascii s)))

(defun ascii-braille-overlay-put-one ()
  "Put overlay on current occurrence of unicode braille after a match."
  (let ((ov (make-overlay (match-beginning 0) (match-end 0)))
	(ascii-braille (ascii-braille-to-ascii (match-string 0))))
    ; (overlay-put ov 'face 'ascii-braille-overlay-default-face)
    (overlay-put ov 'invisible t)
    (overlay-put ov 'evaporate t)
    (overlay-put ov 'braille t)
    (add-face-text-property 0 (length ascii-braille) 'ascii-braille-overlay-default-face nil ascii-braille)
    (overlay-put ov 'before-string ascii-braille)))

(defun ascii-braille-overlay-put-all ()
  "Put overlays on all occurrences of unicode braille in the buffer."
  (let* ((case-fold-search nil))
    (save-excursion
      (save-restriction
        (goto-char (point-min))
        (let ((re "[⠀-⠿]+"))
          (while (re-search-forward re nil t)
            (ascii-braille-overlay-put-one)))))))


(define-minor-mode ascii-braille-mode
  "Toggle Ascii Braille mode.
Hide all Unicode Braille and put an overlay with Ascii Braille over top of it."
  ;; The initial value.
  nil<commit_msg>Leave the unicode braille visible<commit_after>;;; ascii-braille.el --- Replace Unicode Braille with Ascii Braille overlays

;; Copyright (C) 2020 <NAME>

;; Author: <NAME> <<EMAIL>>
;; Version: 0.1
;; URL: https://github.com/liblouis/ascii-braille-overlay/
;; Keywords: faces, matching, braille
;; Package-Requires: ((emacs "24.3") (ht "2.2"))

;; 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
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Replace unicode braille with ascii braille overlays while. It was
;; originally inspired by the package `symbol-overlays'.

;; Usage

;; Toggle the `ascii-braille-mode' minor mode to see the unicode
;; braille in your buffer as ascii braille. Disabling the minor will
;; remove all overlays.

;; TODO

;; I suppose it would be nice if you could edit the ascii braille and
;; have it reflected in the unicode braille.

;;; Code:

(require 'ht)

(defconst ascii-braille-unicode-to-ascii-map
  (ht
   (?⠀ ? )
   (?⠁ ?a)
   (?⠃ ?b)
   (?⠉ ?c)
   (?⠙ ?d)
   (?⠑ ?e)
   (?⠋ ?f)
   (?⠛ ?g)
   (?⠓ ?h)
   (?⠊ ?i)
   (?⠚ ?j)
   (?⠅ ?k)
   (?⠇ ?l)
   (?⠍ ?m)
   (?⠝ ?n)
   (?⠕ ?o)
   (?⠏ ?p)
   (?⠟ ?q)
   (?⠗ ?r)
   (?⠎ ?s)
   (?⠞ ?t)
   (?⠥ ?u)
   (?⠧ ?v)
   (?⠺ ?w)
   (?⠭ ?x)
   (?⠽ ?y)
   (?⠵ ?z)
   (?⠬ ?0)
   (?⠡ ?1)
   (?⠣ ?2)
   (?⠩ ?3)
   (?⠹ ?4)
   (?⠱ ?5)
   (?⠫ ?6)
   (?⠻ ?7)
   (?⠳ ?8)
   (?⠪ ?9)
   (?⠯ ?&)
   (?⠿ ?%)
   (?⠷ ?{)
   (?⠮ ?~)
   (?⠾ ?})
   (?⠂ ?,)
   (?⠆ ?\;)
   (?⠒ ?:)
   (?⠲ ?/)
   (?⠢ ??)
   (?⠖ ?+)
   (?⠶ ?=)
   (?⠦ ?()
   (?⠔ ?*)
   (?⠴ ?))
   (?⠄ ?.)
   (?⠤ ?-)
   (?⠌ ?|)
   (?⠜ ?`)
   (?⠼ ?#)
   (?⠈ ?\")
   (?⠐ ?!)
   (?⠘ ?>)
   (?⠨ ?$)
   (?⠸ ?_)
   (?⠰ ?<)
   (?⠠ ?')))

(defgroup ascii-braille nil
  "Convert unicode braille to ascii braille using overlays."
  :group 'convenience)

(defface ascii-braille-overlay-default-face
  '((t (:inherit highlight)))
  "Ascii braille overlay default face"
  :group 'ascii-braille)

(defun ascii-braille-unicode-to-ascii (char)
  "Convert a unicode braille char to ascii braille. If the char
is not a unicode braille char just return the char itself."
  (ht-get ascii-braille-unicode-to-ascii-map char char))

(defun ascii-braille-to-ascii (s)
  "Convert a unicode braille string to a ascii braille string."
  (seq-concatenate 'string (seq-map #'ascii-braille-unicode-to-ascii s)))

(defun ascii-braille-overlay-put-one ()
  "Put overlay on current occurrence of unicode braille after a match."
  (let ((ov (make-overlay (match-beginning 0) (match-end 0)))
	(ascii-braille (ascii-braille-to-ascii (match-string 0))))
    ; (overlay-put ov 'face 'ascii-braille-overlay-default-face)
    ;(overlay-put ov 'invisible t)
    (overlay-put ov 'evaporate t)
    (overlay-put ov 'braille t)
    (add-face-text-property 0 (length ascii-braille) 'ascii-braille-overlay-default-face nil ascii-braille)
    (overlay-put ov 'before-string ascii-braille)))

(defun ascii-braille-overlay-put-all ()
  "Put overlays on all occurrences of unicode braille in the buffer."
  (let* ((case-fold-search nil))
    (save-excursion
      (save-restriction
        (goto-char (point-min))
        (let ((re "[⠀-⠿]+"))
          (while (re-search-forward re nil t)
            (ascii-braille-overlay-put-one)))))))


(define-minor-mode ascii-braille-mode
  "Toggle Ascii Braille mode.
Hide all Unicode Braille and put an overlay with Ascii Braille over top of it."
  ;; The initial value.
  nil
{'fraction_non_alphanumeric': 0.18369937793576235, 'fraction_numerical': 0.006601498032245779, 'mean_word_length': 2.9647710115752393, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357053', 'n_tokens_mistral': 3400, 'n_tokens_neox': 3122, 'n_words': 951}