unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Raffaele Ricciardi <rfflrccrd@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: forward/backward-sentence in programming modes
Date: Sat, 06 Dec 2014 18:20:30 +0100	[thread overview]
Message-ID: <cegs78Fsip2U1@mid.individual.net> (raw)
In-Reply-To: <mailman.15351.1417819507.1147.help-gnu-emacs@gnu.org>

On 05/12/14 23:44, Marcin Borkowski wrote:
> But what about, say,
> Python or C mode or other ones?

In Python Mode (from "python.el"):
  - M-a runs the command python-nav-backward-block
  - M-e runs the command python-nav-forward-block
  - M-k runs the command kill-sentence

For consistency, M-k could kill to the end of block, instead.  Here is 
an idea:

--

(defun point-after/rr ($movement-command &rest $args)
   "Return what the value of point would be after executing 
$MOVEMENT-COMMAND
with $ARGS."
   (save-excursion
     (apply $movement-command $args)
     (point)))


(defun python-kill-block/rr (&optional $arg)
   "Kill from point to end of Python block.  It doesn't fix indentation.

With $ARG, repeat.  With negative argument, kill $ARG times
backward to previous Python block."
   (interactive "p")
   (or $arg (setq $arg 1))
   (kill-region (point)
                (point-after/rr #'python-nav-forward-block $arg)))


(define-key python-mode-map (kbd "M-k") #'python-kill-block/rr)

--

 > Any ideas?

Context-sensitive versions of M-a and M-e could deal with sentences when 
in comments or strings, and do something else in code (like Python Mode 
does).


  parent reply	other threads:[~2014-12-06 17:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.15351.1417819507.1147.help-gnu-emacs@gnu.org>
2014-12-05 22:59 ` forward/backward-sentence in programming modes Raffaele Ricciardi
2014-12-06 17:20 ` Raffaele Ricciardi [this message]
2014-12-05 22:44 Marcin Borkowski

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=cegs78Fsip2U1@mid.individual.net \
    --to=rfflrccrd@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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).