comparison lisp/viper/viper-ex.el @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents bfd6434d15b3
children acd284d43ca1
comparison
equal deleted inserted replaced
184:bcd2674570bf 185:3d6bfa290dbd
324 (defun viper-get-ex-token () 324 (defun viper-get-ex-token ()
325 (save-window-excursion 325 (save-window-excursion
326 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name)) 326 (setq viper-ex-work-buf (get-buffer-create viper-ex-work-buf-name))
327 (set-buffer viper-ex-work-buf) 327 (set-buffer viper-ex-work-buf)
328 (skip-chars-forward " \t|") 328 (skip-chars-forward " \t|")
329 (cond ((looking-at "#") 329 (let ((case-fold-search t))
330 (setq ex-token-type 'command) 330 (cond ((looking-at "#")
331 (setq ex-token (char-to-string (following-char))) 331 (setq ex-token-type 'command)
332 (forward-char 1)) 332 (setq ex-token (char-to-string (following-char)))
333 ((looking-at "[a-z]") (viper-get-ex-com-subr)) 333 (forward-char 1))
334 ((looking-at "\\.") 334 ((looking-at "[a-z]") (viper-get-ex-com-subr))
335 (forward-char 1) 335 ((looking-at "\\.")
336 (setq ex-token-type 'dot)) 336 (forward-char 1)
337 ((looking-at "[0-9]") 337 (setq ex-token-type 'dot))
338 (set-mark (point)) 338 ((looking-at "[0-9]")
339 (re-search-forward "[0-9]*") 339 (set-mark (point))
340 (setq ex-token-type 340 (re-search-forward "[0-9]*")
341 (cond ((eq ex-token-type 'plus) 'add-number) 341 (setq ex-token-type
342 ((eq ex-token-type 'minus) 'sub-number) 342 (cond ((eq ex-token-type 'plus) 'add-number)
343 (t 'abs-number))) 343 ((eq ex-token-type 'minus) 'sub-number)
344 (setq ex-token (string-to-int (buffer-substring (point) (mark t))))) 344 (t 'abs-number)))
345 ((looking-at "\\$") 345 (setq ex-token
346 (forward-char 1) 346 (string-to-int (buffer-substring (point) (mark t)))))
347 (setq ex-token-type 'end)) 347 ((looking-at "\\$")
348 ((looking-at "%") 348 (forward-char 1)
349 (forward-char 1) 349 (setq ex-token-type 'end))
350 (setq ex-token-type 'whole)) 350 ((looking-at "%")
351 ((looking-at "+") 351 (forward-char 1)
352 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]")) 352 (setq ex-token-type 'whole))
353 (forward-char 1) 353 ((looking-at "+")
354 (insert "1") 354 (cond ((or (looking-at "+[-+]") (looking-at "+[\n|]"))
355 (backward-char 1) 355 (forward-char 1)
356 (insert "1")
357 (backward-char 1)
356 (setq ex-token-type 'plus)) 358 (setq ex-token-type 'plus))
357 ((looking-at "+[0-9]") 359 ((looking-at "+[0-9]")
358 (forward-char 1) 360 (forward-char 1)
359 (setq ex-token-type 'plus)) 361 (setq ex-token-type 'plus))
360 (t 362 (t
361 (error viper-BadAddress)))) 363 (error viper-BadAddress))))
362 ((looking-at "-") 364 ((looking-at "-")
363 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]")) 365 (cond ((or (looking-at "-[-+]") (looking-at "-[\n|]"))
364 (forward-char 1) 366 (forward-char 1)
365 (insert "1") 367 (insert "1")
366 (backward-char 1) 368 (backward-char 1)
367 (setq ex-token-type 'minus)) 369 (setq ex-token-type 'minus))
368 ((looking-at "-[0-9]") 370 ((looking-at "-[0-9]")
369 (forward-char 1) 371 (forward-char 1)
370 (setq ex-token-type 'minus)) 372 (setq ex-token-type 'minus))
371 (t 373 (t
372 (error viper-BadAddress)))) 374 (error viper-BadAddress))))
373 ((looking-at "/") 375 ((looking-at "/")
374 (forward-char 1) 376 (forward-char 1)
375 (set-mark (point)) 377 (set-mark (point))
376 (let ((cont t)) 378 (let ((cont t))
377 (while (and (not (eolp)) cont) 379 (while (and (not (eolp)) cont)
378 ;;(re-search-forward "[^/]*/") 380 ;;(re-search-forward "[^/]*/")
379 (re-search-forward "[^/]*\\(/\\|\n\\)") 381 (re-search-forward "[^/]*\\(/\\|\n\\)")
380 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/")) 382 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\/"))
381 (setq cont nil)))) 383 (setq cont nil))))
382 (backward-char 1) 384 (backward-char 1)
383 (setq ex-token (buffer-substring (point) (mark t))) 385 (setq ex-token (buffer-substring (point) (mark t)))
384 (if (looking-at "/") (forward-char 1)) 386 (if (looking-at "/") (forward-char 1))
385 (setq ex-token-type 'search-forward)) 387 (setq ex-token-type 'search-forward))
386 ((looking-at "\\?") 388 ((looking-at "\\?")
387 (forward-char 1) 389 (forward-char 1)
388 (set-mark (point)) 390 (set-mark (point))
389 (let ((cont t)) 391 (let ((cont t))
390 (while (and (not (eolp)) cont) 392 (while (and (not (eolp)) cont)
391 ;;(re-search-forward "[^\\?]*\\?") 393 ;;(re-search-forward "[^\\?]*\\?")
392 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)") 394 (re-search-forward "[^\\?]*\\(\\?\\|\n\\)")
393 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?")) 395 (if (not (viper-looking-back "[^\\\\]\\(\\\\\\\\\\)*\\\\\\?"))
394 (setq cont nil)) 396 (setq cont nil))
395 (backward-char 1) 397 (backward-char 1)
396 (if (not (looking-at "\n")) (forward-char 1)))) 398 (if (not (looking-at "\n")) (forward-char 1))))
397 (setq ex-token-type 'search-backward) 399 (setq ex-token-type 'search-backward)
398 (setq ex-token (buffer-substring (1- (point)) (mark t)))) 400 (setq ex-token (buffer-substring (1- (point)) (mark t))))
399 ((looking-at ",") 401 ((looking-at ",")
400 (forward-char 1) 402 (forward-char 1)
401 (setq ex-token-type 'comma)) 403 (setq ex-token-type 'comma))
402 ((looking-at ";") 404 ((looking-at ";")
403 (forward-char 1) 405 (forward-char 1)
404 (setq ex-token-type 'semi-colon)) 406 (setq ex-token-type 'semi-colon))
405 ((looking-at "[!=><&~]") 407 ((looking-at "[!=><&~]")
406 (setq ex-token-type 'command) 408 (setq ex-token-type 'command)
407 (setq ex-token (char-to-string (following-char))) 409 (setq ex-token (char-to-string (following-char)))
408 (forward-char 1)) 410 (forward-char 1))
409 ((looking-at "'") 411 ((looking-at "'")
410 (setq ex-token-type 'goto-mark) 412 (setq ex-token-type 'goto-mark)
411 (forward-char 1) 413 (forward-char 1)
412 (cond ((looking-at "'") (setq ex-token nil)) 414 (cond ((looking-at "'") (setq ex-token nil))
413 ((looking-at "[a-z]") (setq ex-token (following-char))) 415 ((looking-at "[a-z]") (setq ex-token (following-char)))
414 (t (error "Marks are ' and a-z"))) 416 (t (error "Marks are ' and a-z")))
415 (forward-char 1)) 417 (forward-char 1))
416 ((looking-at "\n") 418 ((looking-at "\n")
417 (setq ex-token-type 'end-mark) 419 (setq ex-token-type 'end-mark)
418 (setq ex-token "goto")) 420 (setq ex-token "goto"))
419 (t 421 (t
420 (error viper-BadExCommand))))) 422 (error viper-BadExCommand))))))
421 423
422 ;; Reads Ex command. Tries to determine if it has to exit because command 424 ;; Reads Ex command. Tries to determine if it has to exit because command
423 ;; is complete or invalid. If not, keeps reading command. 425 ;; is complete or invalid. If not, keeps reading command.
424 (defun ex-cmd-read-exit () 426 (defun ex-cmd-read-exit ()
425 (interactive) 427 (interactive)