From: Yuri Khan <yuri.v.khan@gmail.com>
To: "R. Diez" <rdiezmail-emacs@yahoo.de>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Skipping words with C-<right> like other editors do
Date: Tue, 17 Apr 2018 00:31:16 +0700 [thread overview]
Message-ID: <CAP_d_8WW2eEw2yjXPojRp=i+UYmiXvzO7JzC2hd9n9NQuEwUyw@mail.gmail.com> (raw)
In-Reply-To: <CAP_d_8Xjpm-8EpFRw=uwCEdeb-3wNx9FFXQMnV9DS_0OiYHgpg@mail.gmail.com>
On Mon, Apr 16, 2018 at 3:22 PM, Yuri Khan <yuri.v.khan@gmail.com> wrote:
>>> !text! ---! ^^^! ***! ///! ;;;! aa!-!xx! bb!
>>> !text !--- !^^^ !*** !/// !;;; !aa!-!xx !bb!
> * Emacs makes much fewer stops in comparison with other editors.
> Namely, it stops only at transitions from letters to non-letters,
> while most other editors stop at transitions from letters to
> whitespace, letters to punctuation, and punctuation to whitespace.
I came up with the following functions. Usage:
(require 'yk-word)
(global-set-key [remap forward-word] 'yk-word-forward)
(global-set-key [remap backward-word] 'yk-word-backward)
(global-set-key [remap left-word] 'yk-word-left)
(global-set-key [remap right-word] 'yk-word-right)
(global-set-key [remap kill-word] 'yk-word-kill-forward)
(global-set-key [remap backward-kill-word] 'yk-word-kill-backward)
=== : yk-word.el
(defun yk-word--motion (count skip char-at)
"Move point COUNT words in the direction defined by SKIP and CHAR-AT."
(let ((table (make-syntax-table (syntax-table))))
(modify-syntax-entry ?\n "-" table)
(with-syntax-table table
(dotimes (_ count)
(funcall skip "-")
(pcase (funcall char-at (point))
('nil)
((app char-syntax ?w) (funcall skip "w"))
(_ (funcall skip "^-w"))))))
t)
(defun yk-word-forward (&optional count)
"Move point COUNT words forward."
(interactive "^p")
(if (and count (> 0 count))
(yk-word-backward (- count))
(yk-word--motion (or count 1) #'skip-syntax-forward #'char-after)))
(defun yk-word-backward (&optional count)
"Move point COUNT words backward."
(interactive "^p")
(if (and count (> 0 count))
(yk-word-forward (- count))
(yk-word--motion (or count 1) #'skip-syntax-backward #'char-before)))
(defun yk-word-right (&optional count)
"Move point COUNT words to the right."
(interactive "^p")
(if (eq (current-bidi-paragraph-direction) 'left-to-right)
(yk-word-forward n)
(yk-word-backward n)))
(defun yk-word-left (&optional count)
"Move point COUNT words to the left."
(interactive "^p")
(if (eq (current-bidi-paragraph-direction) 'left-to-right)
(yk-word-backward n)
(yk-word-forward n)))
(defun yk-word-kill-forward (count)
"Kill COUNT words after point."
(interactive "p")
(let ((start (point)))
(yk-word-forward count)
(kill-region start (point))))
(defun yk-word-kill-backward (count)
"Kill COUNT words before point."
(interactive "p")
(let ((start (point)))
(yk-word-backward count)
(kill-region start (point))))
(defun yk-word-delete-forward (count)
"Delete COUNT words after point."
(interactive "p")
(let ((start (point)))
(yk-word-forward count)
(delete-region start (point))))
(defun yk-word-delete-backward (count)
"Delete COUNT words before point."
(interactive "p")
(let ((start (point)))
(yk-word-backward count)
(delete-region start (point))))
(provide 'yk-word)
next prev parent reply other threads:[~2018-04-16 17:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <778085015.663724.1523818187137.ref@mail.yahoo.com>
2018-04-15 18:49 ` Skipping words with C-<right> like other editors do R. Diez
2018-04-15 22:09 ` Skip Montanaro
[not found] ` <mailman.12470.1523830225.27995.help-gnu-emacs@gnu.org>
2018-04-15 22:17 ` Emanuel Berg
[not found] ` <mailman.12459.1523825033.27995.help-gnu-emacs@gnu.org>
2018-04-15 21:43 ` Emanuel Berg
2018-04-15 21:54 ` Tim Johnson
2018-04-15 23:34 ` James K. Lowden
2018-04-16 8:22 ` Yuri Khan
2018-04-16 17:31 ` Yuri Khan [this message]
2018-04-16 18:49 ` Stefan Monnier
2018-04-16 19:23 ` Yuri Khan
2018-04-17 9:27 ` Yuri Khan
2018-04-17 12:09 ` Stefan Monnier
2018-04-18 8:59 ` Yuri Khan
[not found] ` <mailman.12492.1523866951.27995.help-gnu-emacs@gnu.org>
2018-04-16 23:53 ` James K. Lowden
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='CAP_d_8WW2eEw2yjXPojRp=i+UYmiXvzO7JzC2hd9n9NQuEwUyw@mail.gmail.com' \
--to=yuri.v.khan@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=rdiezmail-emacs@yahoo.de \
/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.
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).