~zge/kaomoji

1ad8804546a9eac61b07e7b871983e40f0c14b44 — Philip K 1 year, 5 months ago 02ada56 0.1.0
fixed typo (kamoji -> kaomoji)
2 files changed, 54 insertions(+), 56 deletions(-)

R KAMOJIS => KAOMOJIS
R kamoji.el => kaomoji.el
R KAMOJIS => KAOMOJIS +0 -0

R kamoji.el => kaomoji.el +54 -56
@@ 1,10 1,10 @@
;;; kamoji.el --- easily insert kamojis -*- lexical-binding: t -*-
;;; kaomoji.el --- easily insert kaomojis -*- lexical-binding: t -*-

;; Author: Philip K. <philip@warpmail.net>
;; Version: 0.1.0
;; Package-Requires: ((emacs "24.4"))
;; Keywords: wp
;; URL: https://git.sr.ht/~zge/kamoji.el
;; URL: https://git.sr.ht/~zge/kaomoji.el

;; This file is NOT part of Emacs.
;;


@@ 16,7 16,7 @@

;;; Commentary:
;; 
;; Kamojis are eastern/Japanese emoticons, which are usually displayed
;; Kaomojis are eastern/Japanese emoticons, which are usually displayed
;; horizontally, as opposed to the western vertical variants (":^)",
;; ";D", "XP", ...).
;;


@@ 24,17 24,17 @@
;; harder to type unicode symbols, which often makes it more difficult
;; to type, or impossible if you don't know the symbols names/numbers.
;;
;; This package tries to make it easier to use kamojis, by using
;; This package tries to make it easier to use kaomojis, by using
;; `completing-read' and different categories. The main user functions
;; are therefore `kamoji-insert' to insert a kamoji at point, and
;; `kamoji-insert-kill-ring' to push a kamoji onto the kill ring.
;; are therefore `kaomoji-insert' to insert a kaomoji at point, and
;; `kaomoji-insert-kill-ring' to push a kaomoji onto the kill ring.
;;
;; The emoticons aren't stored in this file, but (usually) in the
;; KAMOJIS file that should be in the same directory as this source
;; file. This file is parsed by `kamoji--parse-buffer' and then stored
;; in `kamoji-alist'.
;; KAOMOJIS file that should be in the same directory as this source
;; file. This file is parsed by `kaomoji--parse-buffer' and then stored
;; in `kaomoji-alist'.
;;
;; The kamojis in KAMOJIS have been selected and collected from these
;; The kaomojis in KAOMOJIS have been selected and collected from these
;; sites:
;; - https://wikileaks.org/ciav7p1/cms/page_17760284.html
;; - http://kaomoji.ru/en/


@@ 45,19 45,19 @@

;;; Code:

(defvar kamoji--last-used (make-ring 32)
  "Ring of last kamojis inserted.")
(defvar kamoji--last-category nil
  "Symbol of last category used to insert a kamoji.")
(defvar kaomoji--last-used (make-ring 32)
  "Ring of last kaomojis inserted.")
(defvar kaomoji--last-category nil
  "Symbol of last category used to insert a kaomoji.")



(defun kamoji--parse-buffer (buf)
(defun kaomoji--parse-buffer (buf)
  "Parse a buffer BUF creating a alist.

Categories are delimited by an group separator (ASCII 35), which
are in turn split into tags and kamojis. These two are kept apart
by a record separator (ASCII 36). Both tags and kamojis split
are in turn split into tags and kaomojis. These two are kept apart
by a record separator (ASCII 36). Both tags and kaomojis split
their unit components by unit separators (ASCII 37)."
  (with-current-buffer buf
    (let (records end)


@@ 69,77 69,75 @@ their unit components by unit separators (ASCII 37)."
                                       (point-min)
                                       (1- (search-forward "")))
                                      ""))
                 (kamojis (split-string (buffer-substring
                 (kaomojis (split-string (buffer-substring
                                         (point) (point-max)) "")))
            (dolist (name names)
              (push (cons (string-trim-left name) kamojis)
              (push (cons (string-trim-left name) kaomojis)
                    records))))
        (goto-char end))
      records)))

(defun kamoji-parse-file (filename)
  "Parse FILENAME for a list of Kamoji categories."
(defun kaomoji-parse-file (filename)
  "Parse FILENAME for a list of Kaomoji categories."
  (with-temp-buffer
    (insert-file-contents filename)
    (kamoji--parse-buffer (current-buffer))))
    (kaomoji--parse-buffer (current-buffer))))

(defconst kamoji-alist
(defconst kaomoji-alist
  (let* ((dir (if load-file-name
                  (file-name-directory load-file-name)
                default-directory))
         (file (expand-file-name "KAMOJIS" dir)))
    (kamoji-parse-file file))
  "Alist of various kamojis.")
         (file (expand-file-name "KAOMOJIS" dir)))
    (kaomoji-parse-file file))
  "Alist of various kaomojis.")



(defun kamoji--select-kamoji (category)
  "General function to interactively select a kamoji.
(defun kaomoji--select-kaomoji (category)
  "General function to interactively select a kaomoji.

Will first query a category from `kamoji-alist', then a specific
kamoji within the category. If CATEGORY is non-nil, don't query
Will first query a category from `kaomoji-alist', then a specific
kaomoji within the category. If CATEGORY is non-nil, don't query
the user and just use that category instead."
  (let* ((moods (mapcar #'car kamoji-alist))
  (let* ((moods (mapcar #'car kaomoji-alist))
         (category (or category (completing-read "Category: " moods nil t)))
         (list (cdr (assoc category kamoji-alist)))
         (kamoji (completing-read (format "Kamoji (%s): " category) list)))
    (setf kamoji--last-category category)
    (ring-insert kamoji--last-used kamoji)
    kamoji))
         (list (cdr (assoc category kaomoji-alist)))
         (kaomoji (completing-read (format "Kaomoji (%s): " category) list)))
    (setf kaomoji--last-category category)
    (ring-insert kaomoji--last-used kaomoji)
    kaomoji))

(defun kamoji--choose-kamoji (arg)
  "Helper function to choose a kamoji.
(defun kaomoji--choose-kaomoji (arg)
  "Helper function to choose a kaomoji.

No prefix argument opens a category then kamoji menu, a single
No prefix argument opens a category then kaomoji menu, a single
prefix ARG argument re-opens the last category, and a double prefix
argument lists the last used kamojis."
  (cond ((and (>= arg 16) (< 0 (ring-size kamoji--last-used)))
         (completing-read "Last inserted Kamojis: " (ring-elements kamoji--last-used)))
        ((>= arg 4) (kamoji--select-kamoji kamoji--last-category))
        (t (kamoji--select-kamoji nil))))
argument lists the last used kaomojis."
  (cond ((and (>= arg 16) (< 0 (ring-size kaomoji--last-used)))
         (completing-read "Last inserted Kaomojis: " (ring-elements kaomoji--last-used)))
        ((>= arg 4) (kaomoji--select-kaomoji kaomoji--last-category))
        (t (kaomoji--select-kaomoji nil))))



;;;###autoload
(defun kamoji-insert-kill-ring (arg)
  "Insert a kamoji directly into `kill-ring'.
(defun kaomoji-insert-kill-ring (arg)
  "Insert a kaomoji directly into `kill-ring'.

See `kamoji--choose-kamoji' in regards to how the prefix argument
See `kaomoji--choose-kaomoji' in regards to how the prefix argument
ARG is handled."
  (interactive "p")
  (kill-new (kamoji--choose-kamoji arg)))
  (kill-new (kaomoji--choose-kaomoji arg)))

;;;###autoload
(defun kamoji-insert (arg)
  "Insert a kamoji directly into the current buffer.
(defun kaomoji-insert (arg)
  "Insert a kaomoji directly into the current buffer.

See `kamoji--choose-kamoji' in regards to how the prefix argument ARG
See `kaomoji--choose-kaomoji' in regards to how the prefix argument ARG
is handled."
  (interactive "p")
  (insert (kamoji--choose-kamoji arg)))
  (insert (kaomoji--choose-kaomoji arg)))

(provide 'kamoji)
(provide 'kaomoji)

(provide 'kamoji)

;;; kamoji.el ends here
;;; kaomoji.el ends here