LoginSignup
1
0

More than 5 years have passed since last update.

Evilでfコマンドなどで句読点にマッチしてほしい

Last updated at Posted at 2014-09-14

Evilでのfコマンド

将来的には何らかの対応があるのでしょうが、fコマンドで日本語の句読点に
マッチしてほしいと思いました。

(defun skk-char-taiou (char)
  (if (symbol-value skk-mode)
      (progn
        (if (eq char ?.)
            (if (or (eq skk-kutouten-type 'jp) (eq skk-kutouten-type 'jp-en))
                (setq char ?)
              (setq char ?) ))
        (if (eq char ?,)
            (if (or (eq skk-kutouten-type 'jp) (eq skk-kutouten-type 'en-jp))
                (setq char ?)
              (setq char ?) ))))
  char)

なんと汚いコードだと思う。これをevil-find-charに入れる。

(evil-define-motion evil-find-char (count char)
  "Move to the next COUNT'th occurrence of CHAR."
  :jump t
  :type inclusive
  (interactive "<c><C>")
  (setq count (or count 1))
  (setq char (skk-char-taiou char))
 (let ((fwd (> count 0)))
    (setq evil-last-find (list #'evil-find-char char fwd))
    (when fwd (forward-char))
    (let ((case-fold-search nil))
      (unless (prog1
                  (search-forward (char-to-string char)
                                  (unless evil-cross-lines
                                    (if fwd
                                        (line-end-position)
                                      (line-beginning-position)))
                                  t count)
                (when fwd (backward-char)))
        (error "Can't find %c" char)))))

一応は目的達成。SKKユーザでない人はどうやるのか
わかりません。すみません。

追記:

一応きれいだと思うコードにしてみました。

(defun skk-char-taiou (char)
  (if (and (symbol-value skk-mode) (not skk-latin-mode))
      (cond ((or (eq skk-kutouten-type 'jp) (eq skk-kutouten-type 'jp-en))
             (if (eq char ?.) ? char) )
            ((or (eq skk-kutouten-type 'jp) (eq skk-kutouten-type 'en-jp))
             (if (eq char ?,) ? char) )
            (t char))
    char))

審美は人それぞれでしょうけれども。

さらに追記:

(advice-add #'evil-find-char :filter-args #'skk-char-taiou-function)
(defun skk-char-taiou-function (args)
  (list (car args) (skk-char-taiou (cadr args))))

としておくと、evil-find-charを汚さないで済むようです。

追記:

バグがありました。

(defun skk-char-taiou (char)
  (if (and (symbol-value skk-mode) (not skk-latin-mode))
      (cond ((eq skk-kutouten-type 'jp)
             (cond ((eq char ?.) ?) 
                   ((eq char ?,) ?)
                   (t char)))
            ((eq skk-kutouten-type 'jp-en)
             (cond ((eq char ?.) ?)
                   ((eq char ?,) ?)
                   (t char)))
            ((eq skk-kutouten-type 'en-jp)
             (cond ((eq char ?.) ?)
                   ((eq char ?,) ?)
                   (t char)))
            ((eq skk-kutouten-type 'en)
             (cond ((eq char ?.) ?)
                   ((eq char ?,) ?)
                   (t char)))
            (t char))
    char))

でした。condの使い方を間違えていました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0