diff options
| author | Michal Nazarewicz | 2016-09-07 15:21:26 +0200 |
|---|---|---|
| committer | Michal Nazarewicz | 2016-09-12 13:25:13 +0200 |
| commit | 728e40088d054516c1cb5f5412cdab73ed84861d (patch) | |
| tree | 2c4a10657dc0174450d10f35fea6d48d9d4f1475 /src | |
| parent | 74c5b735212ccd5f335312db693fd4754fddbce1 (diff) | |
| download | emacs-728e40088d054516c1cb5f5412cdab73ed84861d.tar.gz emacs-728e40088d054516c1cb5f5412cdab73ed84861d.zip | |
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.
Diffstat (limited to 'src')
| -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 6114a6f7857..6c64d6786d4 100644 --- a/src/casefiddle.c +++ b/src/casefiddle.c | |||
| @@ -376,22 +376,27 @@ character positions to operate on. */) | |||
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | static Lisp_Object | 378 | static Lisp_Object |
| 379 | operate_on_word (Lisp_Object arg, ptrdiff_t *newpoint) | 379 | casify_word (enum case_action flag, Lisp_Object arg) |
| 380 | { | 380 | { |
| 381 | Lisp_Object val; | 381 | Lisp_Object beg, end; |
| 382 | ptrdiff_t farend; | 382 | ptrdiff_t newpoint; |
| 383 | EMACS_INT iarg; | 383 | EMACS_INT iarg; |
| 384 | 384 | ||
| 385 | CHECK_NUMBER (arg); | 385 | CHECK_NUMBER (arg); |
| 386 | iarg = XINT (arg); | 386 | iarg = XINT (arg); |
| 387 | farend = scan_words (PT, iarg); | ||
| 388 | if (!farend) | ||
| 389 | farend = iarg > 0 ? ZV : BEGV; | ||
| 390 | 387 | ||
| 391 | *newpoint = PT > farend ? PT : farend; | 388 | newpoint = scan_words (PT, iarg); |
| 392 | XSETFASTINT (val, farend); | 389 | if (!newpoint) |
| 390 | newpoint = iarg > 0 ? ZV : BEGV; | ||
| 391 | |||
| 392 | XSETFASTINT (beg, PT); | ||
| 393 | XSETFASTINT (end, newpoint); | ||
| 394 | if (PT > newpoint) | ||
| 395 | newpoint = PT; | ||
| 396 | |||
| 397 | casify_region (flag, beg, end); | ||
| 393 | 398 | ||
| 394 | return val; | 399 | SET_PT (newpoint); |
| 395 | } | 400 | } |
| 396 | 401 | ||
| 397 | DEFUN ("upcase-word", Fupcase_word, Supcase_word, 1, 1, "p", | 402 | DEFUN ("upcase-word", Fupcase_word, Supcase_word, 1, 1, "p", |
| @@ -404,12 +409,7 @@ With negative argument, convert previous words but do not move. | |||
| 404 | See also `capitalize-word'. */) | 409 | See also `capitalize-word'. */) |
| 405 | (Lisp_Object arg) | 410 | (Lisp_Object arg) |
| 406 | { | 411 | { |
| 407 | Lisp_Object beg, end; | 412 | casify_word (CASE_UP, arg); |
| 408 | ptrdiff_t newpoint; | ||
| 409 | XSETFASTINT (beg, PT); | ||
| 410 | end = operate_on_word (arg, &newpoint); | ||
| 411 | casify_region (CASE_UP, beg, end); | ||
| 412 | SET_PT (newpoint); | ||
| 413 | return Qnil; | 413 | return Qnil; |
| 414 | } | 414 | } |
| 415 | 415 | ||
| @@ -422,12 +422,7 @@ is ignored when moving forward. | |||
| 422 | With negative argument, convert previous words but do not move. */) | 422 | With negative argument, convert previous words but do not move. */) |
| 423 | (Lisp_Object arg) | 423 | (Lisp_Object arg) |
| 424 | { | 424 | { |
| 425 | Lisp_Object beg, end; | 425 | casify_word (CASE_DOWN, arg); |
| 426 | ptrdiff_t newpoint; | ||
| 427 | XSETFASTINT (beg, PT); | ||
| 428 | end = operate_on_word (arg, &newpoint); | ||
| 429 | casify_region (CASE_DOWN, beg, end); | ||
| 430 | SET_PT (newpoint); | ||
| 431 | return Qnil; | 426 | return Qnil; |
| 432 | } | 427 | } |
| 433 | 428 | ||
| @@ -443,12 +438,7 @@ is ignored when moving forward. | |||
| 443 | With negative argument, capitalize previous words but do not move. */) | 438 | With negative argument, capitalize previous words but do not move. */) |
| 444 | (Lisp_Object arg) | 439 | (Lisp_Object arg) |
| 445 | { | 440 | { |
| 446 | Lisp_Object beg, end; | 441 | casify_word (CASE_CAPITALIZE, arg); |
| 447 | ptrdiff_t newpoint; | ||
| 448 | XSETFASTINT (beg, PT); | ||
| 449 | end = operate_on_word (arg, &newpoint); | ||
| 450 | casify_region (CASE_CAPITALIZE, beg, end); | ||
| 451 | SET_PT (newpoint); | ||
| 452 | return Qnil; | 442 | return Qnil; |
| 453 | } | 443 | } |
| 454 | 444 | ||