aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/emulation
diff options
context:
space:
mode:
authorMark Oteiza2017-08-08 15:00:21 -0400
committerMark Oteiza2017-08-08 15:00:21 -0400
commit884d43b43eb51fe91c657ed0780cf85d31522248 (patch)
tree705090b93f988963de8b529c3f0cfe11f8d74cd6 /lisp/emulation
parent4cb0bdd675f0bc3adc130f1f3d037e4d51152396 (diff)
downloademacs-884d43b43eb51fe91c657ed0780cf85d31522248.tar.gz
emacs-884d43b43eb51fe91c657ed0780cf85d31522248.zip
Convert uses of looking-at in viper-ex to following-char
* lisp/emulation/viper-ex.el (viper-get-ex-token): Bind (following-char) and use it in the subsequent cond's clauses. (viper-ex, ex-quit, viper-get-ex-file): Use following-char instead. Convert single branch ifs to when
Diffstat (limited to 'lisp/emulation')
-rw-r--r--lisp/emulation/viper-ex.el99
1 files changed, 47 insertions, 52 deletions
diff --git a/lisp/emulation/viper-ex.el b/lisp/emulation/viper-ex.el
index ca067033e63..185cf990f76 100644
--- a/lisp/emulation/viper-ex.el
+++ b/lisp/emulation/viper-ex.el
@@ -401,13 +401,14 @@ reversed."
401 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) 401 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
402 (set-buffer viper-ex-work-buf) 402 (set-buffer viper-ex-work-buf)
403 (skip-chars-forward " \t|") 403 (skip-chars-forward " \t|")
404 (let ((case-fold-search t)) 404 (let ((case-fold-search t)
405 (cond ((looking-at "#") 405 (char (following-char)))
406 (cond ((= char ?#)
406 (setq ex-token-type 'command) 407 (setq ex-token-type 'command)
407 (setq ex-token (char-to-string (following-char))) 408 (setq ex-token (char-to-string char))
408 (forward-char 1)) 409 (forward-char 1))
409 ((looking-at "[a-z]") (viper-get-ex-com-subr)) 410 ((looking-at "[a-z]") (viper-get-ex-com-subr))
410 ((looking-at "\\.") 411 ((= char ?.)
411 (forward-char 1) 412 (forward-char 1)
412 (setq ex-token-type 'dot)) 413 (setq ex-token-type 'dot))
413 ((looking-at "[0-9]") 414 ((looking-at "[0-9]")
@@ -419,13 +420,13 @@ reversed."
419 (t 'abs-number))) 420 (t 'abs-number)))
420 (setq ex-token 421 (setq ex-token
421 (string-to-number (buffer-substring (point) (mark t))))) 422 (string-to-number (buffer-substring (point) (mark t)))))
422 ((looking-at "\\$") 423 ((= char ?$)
423 (forward-char 1) 424 (forward-char 1)
424 (setq ex-token-type 'end)) 425 (setq ex-token-type 'end))
425 ((looking-at "%") 426 ((= char ?%)
426 (forward-char 1) 427 (forward-char 1)
427 (setq ex-token-type 'whole)) 428 (setq ex-token-type 'whole))
428 ((looking-at "+") 429 ((= char ?+)
429 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]")) 430 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]"))
430 (forward-char 1) 431 (forward-char 1)
431 (insert "1") 432 (insert "1")
@@ -436,7 +437,7 @@ reversed."
436 (setq ex-token-type 'plus)) 437 (setq ex-token-type 'plus))
437 (t 438 (t
438 (error viper-BadAddress)))) 439 (error viper-BadAddress))))
439 ((looking-at "-") 440 ((= char ?-)
440 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]")) 441 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]"))
441 (forward-char 1) 442 (forward-char 1)
442 (insert "1") 443 (insert "1")
@@ -447,7 +448,7 @@ reversed."
447 (setq ex-token-type 'minus)) 448 (setq ex-token-type 'minus))
448 (t 449 (t
449 (error viper-BadAddress)))) 450 (error viper-BadAddress))))
450 ((looking-at "/") 451 ((= char ?/)
451 (forward-char 1) 452 (forward-char 1)
452 (set-mark (point)) 453 (set-mark (point))
453 (let ((cont t)) 454 (let ((cont t))
@@ -459,9 +460,9 @@ reversed."
459 (setq cont nil)))) 460 (setq cont nil))))
460 (backward-char 1) 461 (backward-char 1)
461 (setq ex-token (buffer-substring (point) (mark t))) 462 (setq ex-token (buffer-substring (point) (mark t)))
462 (if (looking-at "/") (forward-char 1)) 463 (when (= (following-char) ?/) (forward-char 1))
463 (setq ex-token-type 'search-forward)) 464 (setq ex-token-type 'search-forward))
464 ((looking-at "\\?") 465 ((= char ??)
465 (forward-char 1) 466 (forward-char 1)
466 (set-mark (point)) 467 (set-mark (point))
467 (let ((cont t)) 468 (let ((cont t))
@@ -472,27 +473,27 @@ reversed."
472 (line-beginning-position 0))) 473 (line-beginning-position 0)))
473 (setq cont nil)) 474 (setq cont nil))
474 (backward-char 1) 475 (backward-char 1)
475 (if (not (looking-at "\n")) (forward-char 1)))) 476 (when (/= (following-char) ?\n) (forward-char 1))))
476 (setq ex-token-type 'search-backward) 477 (setq ex-token-type 'search-backward)
477 (setq ex-token (buffer-substring (1- (point)) (mark t)))) 478 (setq ex-token (buffer-substring (1- (point)) (mark t))))
478 ((looking-at ",") 479 ((= char ?,)
479 (forward-char 1) 480 (forward-char 1)
480 (setq ex-token-type 'comma)) 481 (setq ex-token-type 'comma))
481 ((looking-at ";") 482 ((= char ?\;)
482 (forward-char 1) 483 (forward-char 1)
483 (setq ex-token-type 'semi-colon)) 484 (setq ex-token-type 'semi-colon))
484 ((looking-at "[!=><&~]") 485 ((looking-at "[!=><&~]")
485 (setq ex-token-type 'command) 486 (setq ex-token-type 'command)
486 (setq ex-token (char-to-string (following-char))) 487 (setq ex-token (char-to-string char))
487 (forward-char 1)) 488 (forward-char 1))
488 ((looking-at "'") 489 ((= char ?\')
489 (setq ex-token-type 'goto-mark) 490 (setq ex-token-type 'goto-mark)
490 (forward-char 1) 491 (forward-char 1)
491 (cond ((looking-at "'") (setq ex-token nil)) 492 (cond ((= (following-char) ?\') (setq ex-token nil))
492 ((looking-at "[a-z]") (setq ex-token (following-char))) 493 ((looking-at "[a-z]") (setq ex-token (following-char)))
493 (t (error "%s" "Marks are ' and a-z"))) 494 (t (error "%s" "Marks are ' and a-z")))
494 (forward-char 1)) 495 (forward-char 1))
495 ((looking-at "\n") 496 ((= char ?\n)
496 (setq ex-token-type 'end-mark) 497 (setq ex-token-type 'end-mark)
497 (setq ex-token "goto")) 498 (setq ex-token "goto"))
498 (t 499 (t
@@ -687,9 +688,9 @@ reversed."
687 (get-buffer-create viper-ex-work-buf-name)) 688 (get-buffer-create viper-ex-work-buf-name))
688 (set-buffer viper-ex-work-buf) 689 (set-buffer viper-ex-work-buf)
689 (skip-chars-forward " \t") 690 (skip-chars-forward " \t")
690 (cond ((looking-at "|") 691 (cond ((= (following-char) ?|)
691 (forward-char 1)) 692 (forward-char 1))
692 ((looking-at "\n") 693 ((= (following-char) ?\n)
693 (setq cont nil)) 694 (setq cont nil))
694 (t (error 695 (t (error
695 "`%s': %s" ex-token viper-SpuriousText))) 696 "`%s': %s" ex-token viper-SpuriousText)))
@@ -994,33 +995,31 @@ reversed."
994 (with-current-buffer (setq viper-ex-work-buf 995 (with-current-buffer (setq viper-ex-work-buf
995 (get-buffer-create viper-ex-work-buf-name)) 996 (get-buffer-create viper-ex-work-buf-name))
996 (skip-chars-forward " \t") 997 (skip-chars-forward " \t")
997 (if (looking-at "!") 998 (when (= (following-char) ?!)
998 (if (and (not (looking-back "[ \t]" (1- (point)))) 999 (if (and (not (memq (preceding-char) '(?\s ?\t)))
999 ;; read doesn't have a corresponding :r! form, so ! is 1000 ;; read doesn't have a corresponding :r! form, so ! is
1000 ;; immediately interpreted as a shell command. 1001 ;; immediately interpreted as a shell command.
1001 (not (string= ex-token "read"))) 1002 (not (string= ex-token "read")))
1002 (progn 1003 (progn
1003 (setq ex-variant t) 1004 (setq ex-variant t)
1004 (forward-char 1) 1005 (forward-char 1)
1005 (skip-chars-forward " \t")) 1006 (skip-chars-forward " \t"))
1006 (setq ex-cmdfile t) 1007 (setq ex-cmdfile t)
1007 (forward-char 1) 1008 (forward-char 1)
1008 (skip-chars-forward " \t"))) 1009 (skip-chars-forward " \t")))
1009 (if (looking-at ">>") 1010 (when (looking-at ">>")
1010 (progn 1011 (setq ex-append t
1011 (setq ex-append t 1012 ex-variant t)
1012 ex-variant t) 1013 (forward-char 2)
1013 (forward-char 2) 1014 (skip-chars-forward " \t"))
1014 (skip-chars-forward " \t"))) 1015 (when (= (following-char) ?+)
1015 (if (looking-at "+") 1016 (forward-char 1)
1016 (progn 1017 (set-mark (point))
1017 (forward-char 1) 1018 (re-search-forward "[ \t\n]")
1018 (set-mark (point)) 1019 (backward-char 1)
1019 (re-search-forward "[ \t\n]") 1020 (setq ex-offset (buffer-substring (point) (mark t)))
1020 (backward-char 1) 1021 (forward-char 1)
1021 (setq ex-offset (buffer-substring (point) (mark t))) 1022 (skip-chars-forward " \t"))
1022 (forward-char 1)
1023 (skip-chars-forward " \t")))
1024 ;; this takes care of :r, :w, etc., when they get file names 1023 ;; this takes care of :r, :w, etc., when they get file names
1025 ;; from the history list 1024 ;; from the history list
1026 (if (member ex-token '("read" "write" "edit" "visual" "next")) 1025 (if (member ex-token '("read" "write" "edit" "visual" "next"))
@@ -1602,7 +1601,7 @@ reversed."
1602 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc. 1601 ;; skip "!", if it is q!. In Viper q!, w!, etc., behave as q, w, etc.
1603 (with-current-buffer (setq viper-ex-work-buf 1602 (with-current-buffer (setq viper-ex-work-buf
1604 (get-buffer-create viper-ex-work-buf-name)) 1603 (get-buffer-create viper-ex-work-buf-name))
1605 (if (looking-at "!") (forward-char 1))) 1604 (when (= (following-char) ?!) (forward-char 1)))
1606 (if (< viper-expert-level 3) 1605 (if (< viper-expert-level 3)
1607 (save-buffers-kill-emacs) 1606 (save-buffers-kill-emacs)
1608 (kill-buffer (current-buffer)))) 1607 (kill-buffer (current-buffer))))
@@ -2322,8 +2321,4 @@ Type `mak ' (including the space) to run make with no args."
2322 (with-output-to-temp-buffer " *viper-info*" 2321 (with-output-to-temp-buffer " *viper-info*"
2323 (princ lines)))))) 2322 (princ lines))))))
2324 2323
2325
2326
2327
2328
2329;;; viper-ex.el ends here 2324;;; viper-ex.el ends here