From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#24398: [PATCH] Refactor common code in {upcase, downcase, capitalize}-word functions Date: Fri, 9 Sep 2016 23:59:19 +0200 Message-ID: <1473458359-29865-1-git-send-email-mina86@mina86.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1473458798 19382 195.159.176.226 (9 Sep 2016 22:06:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 9 Sep 2016 22:06:38 +0000 (UTC) To: 24398@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Sep 10 00:06:34 2016 Return-path: Envelope-to: geb-bug-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 1biTwE-0003XV-QX for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Sep 2016 00:06:23 +0200 Original-Received: from localhost ([::1]:60509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biTwF-00034P-If for geb-bug-gnu-emacs@m.gmane.org; Fri, 09 Sep 2016 18:06:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biTq9-0006vi-V2 for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2016 18:00:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biTq7-0006nD-OY for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2016 18:00:04 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:57236) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biTq7-0006n7-L3 for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2016 18:00:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1biTq7-0002bq-DI for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2016 18:00:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 09 Sep 2016 22:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24398 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14734583819962 (code B ref -1); Fri, 09 Sep 2016 22:00:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Sep 2016 21:59:41 +0000 Original-Received: from localhost ([127.0.0.1]:54948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1biTpk-0002ac-PK for submit@debbugs.gnu.org; Fri, 09 Sep 2016 17:59:40 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:51403) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1biTpi-0002aM-OC for submit@debbugs.gnu.org; Fri, 09 Sep 2016 17:59:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biTpc-0006dL-HE for submit@debbugs.gnu.org; Fri, 09 Sep 2016 17:59:33 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:57346) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biTpc-0006d0-EH for submit@debbugs.gnu.org; Fri, 09 Sep 2016 17:59:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biTpa-0006Sy-0b for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2016 17:59:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biTpX-0006c8-Uu for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2016 17:59:28 -0400 Original-Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:35004) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biTpX-0006bb-Nn for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2016 17:59:27 -0400 Original-Received: by mail-wm0-x233.google.com with SMTP id w12so52821500wmf.0 for ; Fri, 09 Sep 2016 14:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=5vtPthLlTxI/aib89zBGm8jVXo/pANyjegO+ae5QN8Y=; b=kpCuR3k3imF/7Kxv35HpgZhav/qLlDbOrpL+KIK2M7E3QuU5aSODIrvnTvUKiriOS3 zV9RyuD0uqKzYpbthDstL4MDYCFALDV4Gh4dXNrbMvfNpMV2gXGm/XRdPt/DKcKW2PJt VDhTh3lHeuHBNNC8n1dCcsUqCiCSXpnQngZFV4TKMPFC2pDIBWYtGRyqm48t7R58NmmP K6ss5HcK/WG4LFZ/nGyv17GKSd4LaaTu/9X8bvvV2vLNdtU8fVrLF1sg4i4GfV3Q9o0g JcbNJwZUwvr05j9vbCnHQgxHpJyIzJdk/3B7f6wXeijc0u+Odwj0WrjTE6VhnVJaWnPp +58g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=5vtPthLlTxI/aib89zBGm8jVXo/pANyjegO+ae5QN8Y=; b=JWKm7geZmNLb0qYjYXhxaqyWxYP2OpGGvb0L6CqgoisJy3h9YaAsfmbdtSpmPuqomt WqdGrwPgseKkP1vFNxuHHcCIVnGgKDB6CG33xUIpzypUIKhRDLRPi7CqD7Apue2cKJ/I 1slN9hQauYbVU92LK6zsNU8/u/g7H/L9nd5XPThojiIFzM+xnpgznqtmAU97tUgM3KN/ pXSW/MhffwHvEcfIy2OogHFrXEAtQmtKtHuxR7EzGz60aDDhl23uzXlkGuEn5tlcxq6o aGRVjJ9ShNss8MlFtMwTUDXjM2iNLDQrSDfN8IukcoNRYOHw86FYQDN+S5Wo79frajZB J1og== X-Gm-Message-State: AE9vXwN1lObZ/TXF5qYAQSu7bq+n8w8EXisX08Qk40fl24az/w/9Az5qINExZIS+J/Kpu310 X-Received: by 10.195.20.33 with SMTP id gz1mr2216270wjd.75.1473458366316; Fri, 09 Sep 2016 14:59:26 -0700 (PDT) Original-Received: from mpn.zrh.corp.google.com ([172.16.113.135]) by smtp.gmail.com with ESMTPSA id r67sm5291801wmb.14.2016.09.09.14.59.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Sep 2016 14:59:24 -0700 (PDT) Original-Received: by mpn.zrh.corp.google.com (Postfix, from userid 126942) id BC2C01E020D; Fri, 9 Sep 2016 23:59:23 +0200 (CEST) X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:123128 Archived-At: * 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. */) } 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; } -- 2.8.0.rc3.226.g39d4020