From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: Skipping words with C- like other editors do Date: Tue, 17 Apr 2018 00:31:16 +0700 Message-ID: References: <778085015.663724.1523818187137.ref@mail.yahoo.com> <20180415193419.df83012d43d222edbd70e69f@speakeasy.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1523899821 4674 195.159.176.226 (16 Apr 2018 17:30:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 16 Apr 2018 17:30:21 +0000 (UTC) Cc: help-gnu-emacs To: "R. Diez" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Apr 16 19:30:17 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f87xJ-00016v-2u for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Apr 2018 19:30:17 +0200 Original-Received: from localhost ([::1]:60334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f87zP-0007Oe-QR for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Apr 2018 13:32:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f87yc-0007Mu-UA for help-gnu-emacs@gnu.org; Mon, 16 Apr 2018 13:31:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f87yc-0004So-1A for help-gnu-emacs@gnu.org; Mon, 16 Apr 2018 13:31:38 -0400 Original-Received: from mail-oi0-x234.google.com ([2607:f8b0:4003:c06::234]:40689) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f87yb-0004S9-Si for help-gnu-emacs@gnu.org; Mon, 16 Apr 2018 13:31:37 -0400 Original-Received: by mail-oi0-x234.google.com with SMTP id x9-v6so15321667oig.7 for ; Mon, 16 Apr 2018 10:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=hpWGOMms4mDXWmT9e6JDtEIA3NSOXcLWG1EuPEtFKXc=; b=cR4xvYNNqy9rQtq0ojyBxfl3CzgtxaOAink4IaT8Zrrw0+OOnzIZaruLpiOOFyk6iz JwZTcxvJYUtmnuguqoiGo0QQxx0+owM5Ere6QLbPWSh2823+rtEX0KvbBy4r1knJi4nb n2eJ/rL7izzjEyTDjgfSZ89knaICrkr15R+6hXtPAOik7o+HHvapUu5Rzg+CjrYD9pOW jMFsSoW8zkwlKmHKUX18cY6a8aZkv1GO5VpkLj9zoB6VpO/eYfYPILUU8/xg7qmWzKb1 5tOFGTrDLw6I/Neqt0xu1iZaCINHhX32Qm2j5B3UnepRoxxntLix1PX6SxGcmAUwpSaZ J2bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=hpWGOMms4mDXWmT9e6JDtEIA3NSOXcLWG1EuPEtFKXc=; b=sdj3pd4B65vMpUa3iJWriUN0pfVFY1sqLf/fwS93lBZrAFrtAHQjoRyquZuCHct5f+ V3v/XhSYpbbgpSatg4J8suWHYTV3IBAEfm760mDhXFoKVH/3T14baScB2fFlLAeQdnrt 3flnquXiICsLHYH1lPn+C/7xr6jthh7UEdvq3bYPP9RwC84x26ZqcAOUMuAOl4LixEwH xU+QvG2zqE4YGR8Zt1ADthDWpX1iBuXVrAx2FnZQ2uEcJU5DKRdBWsgrXbBPmmOxh0GU ZcbvwEr+4GWCB9jaInZUhwNdO69/nt07vHOojYf9g1acIwaHeuEKxfqvttX1wNCxuMJ4 Lfkg== X-Gm-Message-State: ALQs6tAJKZxVqpIcC0O4zvq03csbFh2LS3LNLcR+/qPQESv7B8Q8cVU0 E+WAD23c9LazocaPnknKNG6UnH/4Mv51VTNdWo8= X-Google-Smtp-Source: AIpwx49DBZJHnORZOY+FEvy+s61TdoKgO7mLHvBEaqSMZVytAWEDBNOMW6A8Bgl8PVtLQ1QMz1QqtxJEICNarHSXpZQ= X-Received: by 2002:aca:6c57:: with SMTP id h84-v6mr15845934oic.50.1523899897233; Mon, 16 Apr 2018 10:31:37 -0700 (PDT) Original-Received: by 10.74.186.8 with HTTP; Mon, 16 Apr 2018 10:31:16 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: VejCMoILar_L0Rcex7AdM_2ssS0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::234 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116548 Archived-At: On Mon, Apr 16, 2018 at 3:22 PM, Yuri Khan 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)