a13 / reverse-im.el

116 stars 4 forks source link

Reverse mapping for isearch #11

Closed jurta closed 4 years ago

jurta commented 4 years ago

Hi @a13

Would it be nice if reverse-im.el also supported reverse mappings in isearch mode as well?

For example, when the buffer contains text like test, then using isearch with Cyrillic letters C-s тест will find Latin letters test.

This feature is available now in Emacs 27 using char-fold. Here is sample code that makes this possible.

Do you think it makes sense to integrate this to the package reverse-im.el?


(setq search-default-mode #'char-fold-to-regexp)

(require 'char-fold)

(setq char-fold-symmetric t)

;; Allow searching with Cyrillic translit
;; https://en.wikipedia.org/wiki/Transliteration
;; https://en.wikipedia.org/wiki/Romanization_of_Russian#Transliteration_table
(setq char-fold-include
      (append char-fold-include
              '((?а "a")
                (?б "b")
                (?в "v" "w")
                (?г "g")
                (?д "d")
                (?е "e")
                (?ё "jo" "yo")
                (?ж "v" "zh")
                (?з "z")
                (?и "i")
                (?й "j" "y")
                (?к "k")
                (?л "l")
                (?м "m")
                (?н "n")
                (?о "o")
                (?п "p")
                (?р "r")
                (?с "s")
                (?т "t")
                (?у "u")
                (?ф "f")
                (?х "h")
                (?ц "c")
                (?ч "ch")
                (?ш "sh")
                (?щ "sch")
                ;; (?ъ "")
                (?ы "y")
                ;; (?ь "")
                (?э "e")
                (?ю "ju" "yu")
                (?я "ja" "ya"))))

(char-fold-update-table)
a13 commented 4 years ago

Hi! It would be a nice feature, but I don't use isearch, so I don't know when I will have time to take a deeper look.

a13 commented 4 years ago

Wow, I realized that swiper supports char folding out of the box! The task is getting more real.

P.S. char-fold-include has a setter, so no need to (char-fold-update-table) manually if set with customize

a13 commented 4 years ago

@jurta Merged, thanks!