unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 52605@debbugs.gnu.org
Subject: bug#52605: [PATCH] Add isearch-emoji-by-name
Date: Sat, 18 Dec 2021 19:55:02 +0100	[thread overview]
Message-ID: <m135mpyc8p.fsf@yahoo.es> (raw)
In-Reply-To: m135mpyc8p.fsf.ref@yahoo.es

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]


This patch adds support for searching a buffer for Emojis without
needing to copy and paste them from another buffer or leaving isearch.
Isearch already provides some methods to search for non-ASCII
characters, so I decided to extend the package to search for Emoji as
well.

With this patch, during an incremental search, if you press 'C-x 8 e
RET', it will ask you for an Emoji character by name and insert it into
the search string.  A prefix argument N will insert N copies of the
character.

If you agree that this feature is sound and makes sense, please review
it and send me feedback or install it for me (I don't have commit
rights).  Perhaps a similar feature is also needed for query and
replace.

Thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-isearch-emoji-by-name.patch --]
[-- Type: text/x-patch, Size: 3588 bytes --]

From a899d6199d27ffefd01b764da9c7f37bb11466f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <mardani29@yahoo.es>
Date: Sat, 18 Dec 2021 19:29:50 +0100
Subject: [PATCH] Add isearch-emoji-by-name

* lisp/isearch.el (isearch-emoji-by-name): Add a new command to insert
Emoji characters into incremental search strings.
(isearch-mode-map): Bind it to 'C-x 8 e RET'.
(isearch-menu-bar-map): Add it to the menu bar.
* doc/emacs/search.texi (Special Isearch): Update the documentation to
mention the new command.
* etc/NEWS: And advertise it.
---
 doc/emacs/search.texi |  7 +++++++
 etc/NEWS              |  5 +++++
 lisp/isearch.el       | 19 +++++++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index fbbb1f6e68..59f6551815 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -443,6 +443,13 @@ Special Isearch
 character into the search string, similar to the usual
 @code{insert-char} command (@pxref{Inserting Text}).
 
+@item
+@findex isearch-emoji-by-name
+@kindex C-x 8 e RET @r{(Incremental Search)}
+Type @kbd{C-x 8 e @key{RET}} (@code{isearch-emoji-by-name}), followed
+by the name of an Emoji.  This adds the specified Emoji into the
+search string.
+
 @item
 @kindex C-^ @r{(Incremental Search)}
 @findex isearch-toggle-input-method
diff --git a/etc/NEWS b/etc/NEWS
index e3665b918a..07f498dab3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -341,6 +341,11 @@ received.
 
 *** New user option 'char-fold-override' omits the default character-folding.
 
++++
+*** New command 'isearch-emoji-by-name'.
+It is bound to 'C-x 8 e RET' during an incremental search and it
+inserts an Emoji character into the search string.
+
 ** New minor mode 'glyphless-display-mode'.
 This allows an easy way to toggle seeing all glyphless characters in
 the current buffer.
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 8815cb4f2d..18ef101fc0 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -668,6 +668,7 @@ isearch-mode-map
     ;; The key translations defined in the C-x 8 prefix should add
     ;; characters to the search string.  See iso-transl.el.
     (define-key map "\C-x8\r" 'isearch-char-by-name)
+    (define-key map "\C-x8e\r" 'isearch-emoji-by-name)
     map)
   "Keymap for `isearch-mode'.")
 
@@ -758,6 +759,8 @@ isearch-menu-bar-map
      :help "Search for literal char"]
     ["Search for char by name" isearch-char-by-name
      :help "Search for character by name"]
+    ["Search for Emoji by name" isearch-emoji-by-name
+     :help "Search for Emoji by name"]
     "---"
     ["Toggle input method" isearch-toggle-input-method
      :help "Toggle input method for search"]
@@ -2747,6 +2750,22 @@ isearch-char-by-name
 					   (mapconcat 'isearch-text-char-description
 						      string ""))))))))
 
+(defun isearch-emoji-by-name (&optional count)
+  "Read an Emoji and add it to the search string.
+With argument, add COUNT copies of the Emoji."
+  (interactive "p")
+  (with-isearch-suspended
+   (let ((emoji (with-temp-buffer
+                  (emoji-search)
+                  (if (and (integerp count) (> count 1))
+                      (apply 'concat (make-list count (buffer-string)))
+                    (buffer-string)))))
+     (when emoji
+       (setq isearch-new-string (concat isearch-string emoji)
+             isearch-new-message (concat isearch-message
+					   (mapconcat 'isearch-text-char-description
+						      emoji "")))))))
+
 (defun isearch-search-and-update ()
   "Do the search and update the display."
   (when (or isearch-success
-- 
2.31.0


       reply	other threads:[~2021-12-18 18:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <m135mpyc8p.fsf.ref@yahoo.es>
2021-12-18 18:55 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-12-18 19:07   ` bug#52605: [PATCH] Add isearch-emoji-by-name Eli Zaretskii
2021-12-19  0:48     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-19  6:53       ` Eli Zaretskii
2021-12-19 11:47         ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-19 11:10   ` Lars Ingebrigtsen
2022-01-09 21:56     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-10  8:07       ` Juri Linkov
2022-01-10 22:44         ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-12  6:02           ` Lars Ingebrigtsen
2022-01-12 17:50             ` Juri Linkov
2022-01-13  6:05               ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m135mpyc8p.fsf@yahoo.es \
    --to=bug-gnu-emacs@gnu.org \
    --cc=52605@debbugs.gnu.org \
    --cc=mardani29@yahoo.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).