all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: 24398@debbugs.gnu.org
Subject: bug#24398: [PATCH] Refactor common code in {upcase, downcase, capitalize}-word functions
Date: Fri,  9 Sep 2016 23:59:19 +0200	[thread overview]
Message-ID: <1473458359-29865-1-git-send-email-mina86@mina86.com> (raw)

* src/casefiddle.c (operate_on_word): Removed in favour of…
(casify_word) …new function which does what operate_on_word did plus
what all of the common code from *-word functions.
(upcase-word, downcase-word, capitalize-word): Move code common between
those functions (pretty much the whole body of those functions) into
casify_word and use that instead of now deleted operato_on_word.
---
 src/casefiddle.c | 44 +++++++++++++++++---------------------------
 1 file changed, 17 insertions(+), 27 deletions(-)

 Unless there are any comments, I’m goning to push this in a few days.

diff --git a/src/casefiddle.c b/src/casefiddle.c
index 6114a6f..6c64d67 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -376,22 +376,27 @@ character positions to operate on.  */)
 }
 \f
 static Lisp_Object
-operate_on_word (Lisp_Object arg, ptrdiff_t *newpoint)
+casify_word (enum case_action flag, Lisp_Object arg)
 {
-  Lisp_Object val;
-  ptrdiff_t farend;
+  Lisp_Object beg, end;
+  ptrdiff_t newpoint;
   EMACS_INT iarg;
 
   CHECK_NUMBER (arg);
   iarg = XINT (arg);
-  farend = scan_words (PT, iarg);
-  if (!farend)
-    farend = iarg > 0 ? ZV : BEGV;
 
-  *newpoint = PT > farend ? PT : farend;
-  XSETFASTINT (val, farend);
+  newpoint = scan_words (PT, iarg);
+  if (!newpoint)
+    newpoint = iarg > 0 ? ZV : BEGV;
+
+  XSETFASTINT (beg, PT);
+  XSETFASTINT (end, newpoint);
+  if (PT > newpoint)
+    newpoint = PT;
+
+  casify_region (flag, beg, end);
 
-  return val;
+  SET_PT (newpoint);
 }
 
 DEFUN ("upcase-word", Fupcase_word, Supcase_word, 1, 1, "p",
@@ -404,12 +409,7 @@ With negative argument, convert previous words but do not move.
 See also `capitalize-word'.  */)
   (Lisp_Object arg)
 {
-  Lisp_Object beg, end;
-  ptrdiff_t newpoint;
-  XSETFASTINT (beg, PT);
-  end = operate_on_word (arg, &newpoint);
-  casify_region (CASE_UP, beg, end);
-  SET_PT (newpoint);
+  casify_word (CASE_UP, arg);
   return Qnil;
 }
 
@@ -422,12 +422,7 @@ is ignored when moving forward.
 With negative argument, convert previous words but do not move.  */)
   (Lisp_Object arg)
 {
-  Lisp_Object beg, end;
-  ptrdiff_t newpoint;
-  XSETFASTINT (beg, PT);
-  end = operate_on_word (arg, &newpoint);
-  casify_region (CASE_DOWN, beg, end);
-  SET_PT (newpoint);
+  casify_word (CASE_DOWN, arg);
   return Qnil;
 }
 
@@ -443,12 +438,7 @@ is ignored when moving forward.
 With negative argument, capitalize previous words but do not move.  */)
   (Lisp_Object arg)
 {
-  Lisp_Object beg, end;
-  ptrdiff_t newpoint;
-  XSETFASTINT (beg, PT);
-  end = operate_on_word (arg, &newpoint);
-  casify_region (CASE_CAPITALIZE, beg, end);
-  SET_PT (newpoint);
+  casify_word (CASE_CAPITALIZE, arg);
   return Qnil;
 }
 \f
-- 
2.8.0.rc3.226.g39d4020






             reply	other threads:[~2016-09-09 21:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-09 21:59 Michal Nazarewicz [this message]
2016-09-10  6:46 ` bug#24398: [PATCH] Refactor common code in {upcase, downcase, capitalize}-word functions Eli Zaretskii
2016-09-12 11:26   ` Michal Nazarewicz

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473458359-29865-1-git-send-email-mina86@mina86.com \
    --to=mina86@mina86.com \
    --cc=24398@debbugs.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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.