diff options
author | Michal Nazarewicz <mina86@mina86.com> | 2016-09-07 15:21:26 +0200 |
---|---|---|
committer | Michal Nazarewicz <mina86@mina86.com> | 2016-09-12 13:25:13 +0200 |
commit | 728e40088d054516c1cb5f5412cdab73ed84861d (patch) | |
tree | 2c4a10657dc0174450d10f35fea6d48d9d4f1475 | |
parent | 74c5b735212ccd5f335312db693fd4754fddbce1 (diff) |
Refactor common code in {upcase,downcase,capitalize}-word functions
* 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 operate_on_word.
-rw-r--r-- | src/casefiddle.c | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/src/casefiddle.c b/src/casefiddle.c index 6114a6f785..6c64d6786d 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; } |