comparison lisp/emulation/viper-util.el @ 49598:0d8b17d428b5

Trailing whitepace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 13:24:35 +0000
parents a37b476e1aec
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49597:e88404e8f2cf 49598:0d8b17d428b5
134 (defsubst viper-color-display-p () 134 (defsubst viper-color-display-p ()
135 (viper-cond-compile-for-xemacs-or-emacs 135 (viper-cond-compile-for-xemacs-or-emacs
136 (eq (device-class (selected-device)) 'color) ; xemacs 136 (eq (device-class (selected-device)) 'color) ; xemacs
137 (x-display-color-p) ; emacs 137 (x-display-color-p) ; emacs
138 )) 138 ))
139 139
140 (defsubst viper-get-cursor-color () 140 (defsubst viper-get-cursor-color ()
141 (viper-cond-compile-for-xemacs-or-emacs 141 (viper-cond-compile-for-xemacs-or-emacs
142 ;; xemacs 142 ;; xemacs
143 (color-instance-name (frame-property (selected-frame) 'cursor-color)) 143 (color-instance-name (frame-property (selected-frame) 'cursor-color))
144 (cdr (assoc 'cursor-color (frame-parameters))) ; emacs 144 (cdr (assoc 'cursor-color (frame-parameters))) ; emacs
145 )) 145 ))
146 146
147 147
148 ;; OS/2 148 ;; OS/2
149 (cond ((eq (viper-device-type) 'pm) 149 (cond ((eq (viper-device-type) 'pm)
150 (fset 'viper-color-defined-p 150 (fset 'viper-color-defined-p
151 (lambda (color) (assoc color pm-color-alist))))) 151 (lambda (color) (assoc color pm-color-alist)))))
152 152
153 153
154 ;; cursor colors 154 ;; cursor colors
155 (defun viper-change-cursor-color (new-color) 155 (defun viper-change-cursor-color (new-color)
156 (if (and (viper-window-display-p) (viper-color-display-p) 156 (if (and (viper-window-display-p) (viper-color-display-p)
157 (stringp new-color) (viper-color-defined-p new-color) 157 (stringp new-color) (viper-color-defined-p new-color)
161 (selected-frame) 'cursor-color (make-color-instance new-color)) 161 (selected-frame) 'cursor-color (make-color-instance new-color))
162 (modify-frame-parameters 162 (modify-frame-parameters
163 (selected-frame) (list (cons 'cursor-color new-color))) 163 (selected-frame) (list (cons 'cursor-color new-color)))
164 ) 164 )
165 )) 165 ))
166 166
167 ;; By default, saves current frame cursor color in the 167 ;; By default, saves current frame cursor color in the
168 ;; viper-saved-cursor-color-in-replace-mode property of viper-replace-overlay 168 ;; viper-saved-cursor-color-in-replace-mode property of viper-replace-overlay
169 (defun viper-save-cursor-color (before-which-mode) 169 (defun viper-save-cursor-color (before-which-mode)
170 (if (and (viper-window-display-p) (viper-color-display-p)) 170 (if (and (viper-window-display-p) (viper-color-display-p))
171 (let ((color (viper-get-cursor-color))) 171 (let ((color (viper-get-cursor-color)))
178 (if (eq before-which-mode 'before-replace-mode) 178 (if (eq before-which-mode 'before-replace-mode)
179 'viper-saved-cursor-color-in-replace-mode 179 'viper-saved-cursor-color-in-replace-mode
180 'viper-saved-cursor-color-in-insert-mode) 180 'viper-saved-cursor-color-in-insert-mode)
181 color))) 181 color)))
182 )))) 182 ))))
183 183
184 184
185 (defsubst viper-get-saved-cursor-color-in-replace-mode () 185 (defsubst viper-get-saved-cursor-color-in-replace-mode ()
186 (or 186 (or
187 (funcall 187 (funcall
188 (if viper-emacs-p 'frame-parameter 'frame-property) 188 (if viper-emacs-p 'frame-parameter 'frame-property)
195 (funcall 195 (funcall
196 (if viper-emacs-p 'frame-parameter 'frame-property) 196 (if viper-emacs-p 'frame-parameter 'frame-property)
197 (selected-frame) 197 (selected-frame)
198 'viper-saved-cursor-color-in-insert-mode) 198 'viper-saved-cursor-color-in-insert-mode)
199 viper-vi-state-cursor-color)) 199 viper-vi-state-cursor-color))
200 200
201 ;; restore cursor color from replace overlay 201 ;; restore cursor color from replace overlay
202 (defun viper-restore-cursor-color(after-which-mode) 202 (defun viper-restore-cursor-color(after-which-mode)
203 (if (viper-overlay-p viper-replace-overlay) 203 (if (viper-overlay-p viper-replace-overlay)
204 (viper-change-cursor-color 204 (viper-change-cursor-color
205 (if (eq after-which-mode 'after-replace-mode) 205 (if (eq after-which-mode 'after-replace-mode)
206 (viper-get-saved-cursor-color-in-replace-mode) 206 (viper-get-saved-cursor-color-in-replace-mode)
207 (viper-get-saved-cursor-color-in-insert-mode)) 207 (viper-get-saved-cursor-color-in-insert-mode))
208 ))) 208 )))
209 209
210 210
211 ;; Check the current version against the major and minor version numbers 211 ;; Check the current version against the major and minor version numbers
212 ;; using op: cur-vers op major.minor If emacs-major-version or 212 ;; using op: cur-vers op major.minor If emacs-major-version or
213 ;; emacs-minor-version are not defined, we assume that the current version 213 ;; emacs-minor-version are not defined, we assume that the current version
214 ;; is hopelessly outdated. We assume that emacs-major-version and 214 ;; is hopelessly outdated. We assume that emacs-major-version and
232 t))) 232 t)))
233 (t 233 (t
234 (error "%S: Invalid op in viper-check-version" op)))) 234 (error "%S: Invalid op in viper-check-version" op))))
235 (cond ((memq op '(= > >=)) nil) 235 (cond ((memq op '(= > >=)) nil)
236 ((memq op '(< <=)) t)))) 236 ((memq op '(< <=)) t))))
237 237
238 238
239 (defun viper-get-visible-buffer-window (wind) 239 (defun viper-get-visible-buffer-window (wind)
240 (if viper-xemacs-p 240 (if viper-xemacs-p
241 (get-buffer-window wind t) 241 (get-buffer-window wind t)
242 (get-buffer-window wind 'visible))) 242 (get-buffer-window wind 'visible)))
243 243
244 244
245 ;; Return line position. 245 ;; Return line position.
246 ;; If pos is 'start then returns position of line start. 246 ;; If pos is 'start then returns position of line start.
247 ;; If pos is 'end, returns line end. If pos is 'mid, returns line center. 247 ;; If pos is 'end, returns line end. If pos is 'mid, returns line center.
248 ;; Pos = 'indent returns beginning of indentation. 248 ;; Pos = 'indent returns beginning of indentation.
249 ;; Otherwise, returns point. Current point is not moved in any case." 249 ;; Otherwise, returns point. Current point is not moved in any case."
284 284
285 285
286 ;; Like move-marker but creates a virgin marker if arg isn't already a marker. 286 ;; Like move-marker but creates a virgin marker if arg isn't already a marker.
287 ;; The first argument must eval to a variable name. 287 ;; The first argument must eval to a variable name.
288 ;; Arguments: (var-name position &optional buffer). 288 ;; Arguments: (var-name position &optional buffer).
289 ;; 289 ;;
290 ;; This is useful for moving markers that are supposed to be local. 290 ;; This is useful for moving markers that are supposed to be local.
291 ;; For this, VAR-NAME should be made buffer-local with nil as a default. 291 ;; For this, VAR-NAME should be made buffer-local with nil as a default.
292 ;; Then, each time this var is used in `viper-move-marker-locally' in a new 292 ;; Then, each time this var is used in `viper-move-marker-locally' in a new
293 ;; buffer, a new marker will be created. 293 ;; buffer, a new marker will be created.
294 (defun viper-move-marker-locally (var pos &optional buffer) 294 (defun viper-move-marker-locally (var pos &optional buffer)
307 (beep 1))) 307 (beep 1)))
308 308
309 309
310 310
311 ;;; List/alist utilities 311 ;;; List/alist utilities
312 312
313 ;; Convert LIST to an alist 313 ;; Convert LIST to an alist
314 (defun viper-list-to-alist (lst) 314 (defun viper-list-to-alist (lst)
315 (let ((alist)) 315 (let ((alist))
316 (while lst 316 (while lst
317 (setq alist (cons (list (car lst)) alist)) 317 (setq alist (cons (list (car lst)) alist))
318 (setq lst (cdr lst))) 318 (setq lst (cdr lst)))
319 alist)) 319 alist))
320 320
321 ;; Convert ALIST to a list. 321 ;; Convert ALIST to a list.
322 (defun viper-alist-to-list (alst) 322 (defun viper-alist-to-list (alst)
323 (let ((lst)) 323 (let ((lst))
324 (while alst 324 (while alst
332 (let ((outalst) (inalst alst)) 332 (let ((outalst) (inalst alst))
333 (while (car inalst) 333 (while (car inalst)
334 (if (string-match regexp (car (car inalst))) 334 (if (string-match regexp (car (car inalst)))
335 (setq outalst (cons (car inalst) outalst))) 335 (setq outalst (cons (car inalst) outalst)))
336 (setq inalst (cdr inalst))) 336 (setq inalst (cdr inalst)))
337 outalst)) 337 outalst))
338 338
339 ;; Filter LIST using REGEXP. Return list whose elements match the regexp. 339 ;; Filter LIST using REGEXP. Return list whose elements match the regexp.
340 (defun viper-filter-list (regexp lst) 340 (defun viper-filter-list (regexp lst)
341 (interactive "s x") 341 (interactive "s x")
342 (let ((outlst) (inlst lst)) 342 (let ((outlst) (inlst lst))
343 (while (car inlst) 343 (while (car inlst)
344 (if (string-match regexp (car inlst)) 344 (if (string-match regexp (car inlst))
345 (setq outlst (cons (car inlst) outlst))) 345 (setq outlst (cons (car inlst) outlst)))
346 (setq inlst (cdr inlst))) 346 (setq inlst (cdr inlst)))
347 outlst)) 347 outlst))
348 348
349 349
350 ;; Append LIS2 to LIS1, both alists, by side-effect and returns LIS1 350 ;; Append LIS2 to LIS1, both alists, by side-effect and returns LIS1
351 ;; LIS2 is modified by filtering it: deleting its members of the form 351 ;; LIS2 is modified by filtering it: deleting its members of the form
352 ;; \(car elt\) such that (car elt') is in LIS1. 352 ;; \(car elt\) such that (car elt') is in LIS1.
353 (defun viper-append-filter-alist (lis1 lis2) 353 (defun viper-append-filter-alist (lis1 lis2)
354 (let ((temp lis1) 354 (let ((temp lis1)
357 (while temp 357 (while temp
358 ;; delete all occurrences 358 ;; delete all occurrences
359 (while (setq elt (assoc (car (car temp)) lis2)) 359 (while (setq elt (assoc (car (car temp)) lis2))
360 (setq lis2 (delq elt lis2))) 360 (setq lis2 (delq elt lis2)))
361 (setq temp (cdr temp))) 361 (setq temp (cdr temp)))
362 362
363 (nconc lis1 lis2))) 363 (nconc lis1 lis2)))
364 364
365 365
366 366
367 ;;; Support for :e, :r, :w file globbing 367 ;;; Support for :e, :r, :w file globbing
378 (cond (ex-unix-type-shell-options) 378 (cond (ex-unix-type-shell-options)
379 )) 379 ))
380 (command (cond (viper-ms-style-os-p (format "\"ls -1 -d %s\"" filespec)) 380 (command (cond (viper-ms-style-os-p (format "\"ls -1 -d %s\"" filespec))
381 (t (format "ls -1 -d %s" filespec)))) 381 (t (format "ls -1 -d %s" filespec))))
382 status) 382 status)
383 (save-excursion 383 (save-excursion
384 (set-buffer (get-buffer-create viper-ex-tmp-buf-name)) 384 (set-buffer (get-buffer-create viper-ex-tmp-buf-name))
385 (erase-buffer) 385 (erase-buffer)
386 (setq status 386 (setq status
387 (if gshell-options 387 (if gshell-options
388 (call-process gshell nil t nil 388 (call-process gshell nil t nil
423 (setq delim ?\") 423 (setq delim ?\")
424 (re-search-forward "[^\"]+" nil t)) ; noerror 424 (re-search-forward "[^\"]+" nil t)) ; noerror
425 ((looking-at "'") 425 ((looking-at "'")
426 (setq delim ?') 426 (setq delim ?')
427 (re-search-forward "[^']+" nil t)) ; noerror 427 (re-search-forward "[^']+" nil t)) ; noerror
428 (t 428 (t
429 (re-search-forward 429 (re-search-forward
430 (concat "[^" skip-chars "]+") nil t))) ;noerror 430 (concat "[^" skip-chars "]+") nil t))) ;noerror
431 (setq fname 431 (setq fname
432 (buffer-substring (match-beginning 0) (match-end 0)))) 432 (buffer-substring (match-beginning 0) (match-end 0))))
433 (if delim 433 (if delim
457 ;; glob windows files 457 ;; glob windows files
458 ;; LIST is expected to be in reverse order 458 ;; LIST is expected to be in reverse order
459 (defun viper-glob-mswindows-files (filespec) 459 (defun viper-glob-mswindows-files (filespec)
460 (let ((case-fold-search t) 460 (let ((case-fold-search t)
461 tmp tmp2) 461 tmp tmp2)
462 (save-excursion 462 (save-excursion
463 (set-buffer (get-buffer-create viper-ex-tmp-buf-name)) 463 (set-buffer (get-buffer-create viper-ex-tmp-buf-name))
464 (erase-buffer) 464 (erase-buffer)
465 (insert filespec) 465 (insert filespec)
466 (goto-char (point-min)) 466 (goto-char (point-min))
467 (setq tmp (viper-get-filenames-from-buffer)) 467 (setq tmp (viper-get-filenames-from-buffer))
468 (while tmp 468 (while tmp
469 (setq tmp2 (cons (directory-files 469 (setq tmp2 (cons (directory-files
470 ;; the directory part 470 ;; the directory part
471 (or (file-name-directory (car tmp)) 471 (or (file-name-directory (car tmp))
472 "") 472 "")
473 t ; return full names 473 t ; return full names
474 ;; the regexp part: globs the file names 474 ;; the regexp part: globs the file names
493 (ring-minus1 (car ring) (ring-length ring))) 493 (ring-minus1 (car ring) (ring-length ring)))
494 ;; don't rotate if dir = 0 494 ;; don't rotate if dir = 0
495 (t (car ring)))) 495 (t (car ring))))
496 (viper-current-ring-item ring) 496 (viper-current-ring-item ring)
497 ))) 497 )))
498 498
499 (defun viper-special-ring-rotate1 (ring dir) 499 (defun viper-special-ring-rotate1 (ring dir)
500 (if (memq viper-intermediate-command 500 (if (memq viper-intermediate-command
501 '(repeating-display-destructive-command 501 '(repeating-display-destructive-command
502 repeating-insertion-from-ring)) 502 repeating-insertion-from-ring))
503 (viper-ring-rotate1 ring dir) 503 (viper-ring-rotate1 ring dir)
504 ;; don't rotate otherwise 504 ;; don't rotate otherwise
505 (viper-ring-rotate1 ring 0))) 505 (viper-ring-rotate1 ring 0)))
506 506
507 ;; current ring item; if N is given, then so many items back from the 507 ;; current ring item; if N is given, then so many items back from the
508 ;; current 508 ;; current
509 (defun viper-current-ring-item (ring &optional n) 509 (defun viper-current-ring-item (ring &optional n)
510 (setq n (or n 0)) 510 (setq n (or n 0))
511 (if (and (ring-p ring) (> (ring-length ring) 0)) 511 (if (and (ring-p ring) (> (ring-length ring) 0))
512 (aref (cdr (cdr ring)) (mod (- (car ring) 1 n) (ring-length ring))))) 512 (aref (cdr (cdr ring)) (mod (- (car ring) 1 n) (ring-length ring)))))
513 513
514 ;; Push item onto ring. The second argument is a ring-variable, not value. 514 ;; Push item onto ring. The second argument is a ring-variable, not value.
515 (defun viper-push-onto-ring (item ring-var) 515 (defun viper-push-onto-ring (item ring-var)
516 (or (ring-p (eval ring-var)) 516 (or (ring-p (eval ring-var))
517 (set ring-var (make-ring (eval (intern (format "%S-size" ring-var)))))) 517 (set ring-var (make-ring (eval (intern (format "%S-size" ring-var))))))
518 (or (null item) ; don't push nil 518 (or (null item) ; don't push nil
530 (and (eq ring-var 'viper-command-ring) 530 (and (eq ring-var 'viper-command-ring)
531 (string-match "\\([0-9]*\e\\|^[ \t]*$\\|escape\\)" 531 (string-match "\\([0-9]*\e\\|^[ \t]*$\\|escape\\)"
532 (viper-array-to-string (this-command-keys)))) 532 (viper-array-to-string (this-command-keys))))
533 (viper-ring-insert (eval ring-var) item)) 533 (viper-ring-insert (eval ring-var) item))
534 ) 534 )
535 535
536 536
537 ;; removing elts from ring seems to break it 537 ;; removing elts from ring seems to break it
538 (defun viper-cleanup-ring (ring) 538 (defun viper-cleanup-ring (ring)
539 (or (< (ring-length ring) 2) 539 (or (< (ring-length ring) 2)
540 (null (viper-current-ring-item ring)) 540 (null (viper-current-ring-item ring))
541 ;; last and previous equal 541 ;; last and previous equal
542 (if (equal (viper-current-ring-item ring) 542 (if (equal (viper-current-ring-item ring)
543 (viper-current-ring-item ring 1)) 543 (viper-current-ring-item ring 1))
544 (viper-ring-pop ring)))) 544 (viper-ring-pop ring))))
545 545
546 ;; ring-remove seems to be buggy, so we concocted this for our purposes. 546 ;; ring-remove seems to be buggy, so we concocted this for our purposes.
547 (defun viper-ring-pop (ring) 547 (defun viper-ring-pop (ring)
548 (let* ((ln (ring-length ring)) 548 (let* ((ln (ring-length ring))
549 (vec (cdr (cdr ring))) 549 (vec (cdr (cdr ring)))
550 (veclen (length vec)) 550 (veclen (length vec))
551 (hd (car ring)) 551 (hd (car ring))
552 (idx (max 0 (ring-minus1 hd ln))) 552 (idx (max 0 (ring-minus1 hd ln)))
553 (top-elt (aref vec idx))) 553 (top-elt (aref vec idx)))
554 554
555 ;; shift elements 555 ;; shift elements
556 (while (< (1+ idx) veclen) 556 (while (< (1+ idx) veclen)
557 (aset vec idx (aref vec (1+ idx))) 557 (aset vec idx (aref vec (1+ idx)))
558 (setq idx (1+ idx))) 558 (setq idx (1+ idx)))
559 (aset vec idx nil) 559 (aset vec idx nil)
560 560
561 (setq hd (max 0 (ring-minus1 hd ln))) 561 (setq hd (max 0 (ring-minus1 hd ln)))
562 (if (= hd (1- ln)) (setq hd 0)) 562 (if (= hd (1- ln)) (setq hd 0))
563 (setcar ring hd) ; move head 563 (setcar ring hd) ; move head
564 (setcar (cdr ring) (max 0 (1- ln))) ; adjust length 564 (setcar (cdr ring) (max 0 (1- ln))) ; adjust length
565 top-elt 565 top-elt
566 )) 566 ))
567 567
568 (defun viper-ring-insert (ring item) 568 (defun viper-ring-insert (ring item)
569 (let* ((ln (ring-length ring)) 569 (let* ((ln (ring-length ring))
570 (vec (cdr (cdr ring))) 570 (vec (cdr (cdr ring)))
571 (veclen (length vec)) 571 (veclen (length vec))
572 (hd (car ring)) 572 (hd (car ring))
573 (vecpos-after-hd (if (= hd 0) ln hd)) 573 (vecpos-after-hd (if (= hd 0) ln hd))
574 (idx ln)) 574 (idx ln))
575 575
576 (if (= ln veclen) 576 (if (= ln veclen)
577 (progn 577 (progn
578 (aset vec hd item) ; hd is always 1+ the actual head index in vec 578 (aset vec hd item) ; hd is always 1+ the actual head index in vec
579 (setcar ring (ring-plus1 hd ln))) 579 (setcar ring (ring-plus1 hd ln)))
580 (setcar (cdr ring) (1+ ln)) 580 (setcar (cdr ring) (1+ ln))
582 (while (and (>= idx vecpos-after-hd) (> ln 0)) 582 (while (and (>= idx vecpos-after-hd) (> ln 0))
583 (aset vec idx (aref vec (1- idx))) 583 (aset vec idx (aref vec (1- idx)))
584 (setq idx (1- idx))) 584 (setq idx (1- idx)))
585 (aset vec vecpos-after-hd item)) 585 (aset vec vecpos-after-hd item))
586 item)) 586 item))
587 587
588 588
589 ;;; String utilities 589 ;;; String utilities
590 590
591 ;; If STRING is longer than MAX-LEN, truncate it and print ...... instead 591 ;; If STRING is longer than MAX-LEN, truncate it and print ...... instead
592 ;; PRE-STRING is a string to prepend to the abbrev string. 592 ;; PRE-STRING is a string to prepend to the abbrev string.
593 ;; POST-STRING is a string to append to the abbrev string. 593 ;; POST-STRING is a string to append to the abbrev string.
594 ;; ABBREV_SIGN is a string to be inserted before POST-STRING 594 ;; ABBREV_SIGN is a string to be inserted before POST-STRING
595 ;; if the orig string was truncated. 595 ;; if the orig string was truncated.
596 (defun viper-abbreviate-string (string max-len 596 (defun viper-abbreviate-string (string max-len
597 pre-string post-string abbrev-sign) 597 pre-string post-string abbrev-sign)
598 (let (truncated-str) 598 (let (truncated-str)
599 (setq truncated-str 599 (setq truncated-str
600 (if (stringp string) 600 (if (stringp string)
601 (substring string 0 (min max-len (length string))))) 601 (substring string 0 (min max-len (length string)))))
602 (cond ((null truncated-str) "") 602 (cond ((null truncated-str) "")
603 ((> (length string) max-len) 603 ((> (length string) max-len)
604 (format "%s%s%s%s" 604 (format "%s%s%s%s"
605 pre-string truncated-str abbrev-sign post-string)) 605 pre-string truncated-str abbrev-sign post-string))
608 ;; tells if we are over a whitespace-only line 608 ;; tells if we are over a whitespace-only line
609 (defsubst viper-over-whitespace-line () 609 (defsubst viper-over-whitespace-line ()
610 (save-excursion 610 (save-excursion
611 (beginning-of-line) 611 (beginning-of-line)
612 (looking-at "^[ \t]*$"))) 612 (looking-at "^[ \t]*$")))
613 613
614 614
615 ;;; Saving settings in custom file 615 ;;; Saving settings in custom file
616 616
617 ;; Save the current setting of VAR in CUSTOM-FILE. 617 ;; Save the current setting of VAR in CUSTOM-FILE.
618 ;; If given, MESSAGE is a message to be displayed after that. 618 ;; If given, MESSAGE is a message to be displayed after that.
642 (if erase-msg 642 (if erase-msg
643 (progn 643 (progn
644 (sit-for 2) 644 (sit-for 2)
645 (message ""))) 645 (message "")))
646 )) 646 ))
647 647
648 ;; Save STRING in CUSTOM-FILE. If PATTERN is non-nil, remove strings that 648 ;; Save STRING in CUSTOM-FILE. If PATTERN is non-nil, remove strings that
649 ;; match this pattern. 649 ;; match this pattern.
650 (defun viper-save-string-in-file (string custom-file &optional pattern) 650 (defun viper-save-string-in-file (string custom-file &optional pattern)
651 (let ((buf (find-file-noselect (substitute-in-file-name custom-file)))) 651 (let ((buf (find-file-noselect (substitute-in-file-name custom-file))))
652 (save-excursion 652 (save-excursion
668 ((fboundp 'file-remote-p) (file-remote-p file-name)) 668 ((fboundp 'file-remote-p) (file-remote-p file-name))
669 (t (require 'ange-ftp) 669 (t (require 'ange-ftp)
670 ;; Can happen only in Emacs, since XEmacs has file-remote-p 670 ;; Can happen only in Emacs, since XEmacs has file-remote-p
671 (ange-ftp-ftp-name file-name)))))) 671 (ange-ftp-ftp-name file-name))))))
672 672
673 673
674 674
675 ;; This is a simple-minded check for whether a file is under version control. 675 ;; This is a simple-minded check for whether a file is under version control.
676 ;; If file,v exists but file doesn't, this file is considered to be not checked 676 ;; If file,v exists but file doesn't, this file is considered to be not checked
677 ;; in and not checked out for the purpose of patching (since patch won't be 677 ;; in and not checked out for the purpose of patching (since patch won't be
678 ;; able to read such a file anyway). 678 ;; able to read such a file anyway).
719 (format 719 (format
720 "File %s is checked in. Check it out? " 720 "File %s is checked in. Check it out? "
721 (viper-abbreviate-file-name file)))) 721 (viper-abbreviate-file-name file))))
722 (with-current-buffer buf 722 (with-current-buffer buf
723 (command-execute checkout-function))))) 723 (command-execute checkout-function)))))
724 724
725 725
726 726
727 727
728 ;;; Overlays 728 ;;; Overlays
729 (defun viper-put-on-search-overlay (beg end) 729 (defun viper-put-on-search-overlay (beg end)
730 (if (viper-overlay-p viper-search-overlay) 730 (if (viper-overlay-p viper-search-overlay)
731 (viper-move-overlay viper-search-overlay beg end) 731 (viper-move-overlay viper-search-overlay beg end)
754 754
755 ;; Replace state 755 ;; Replace state
756 756
757 (defsubst viper-move-replace-overlay (beg end) 757 (defsubst viper-move-replace-overlay (beg end)
758 (viper-move-overlay viper-replace-overlay beg end)) 758 (viper-move-overlay viper-replace-overlay beg end))
759 759
760 (defun viper-set-replace-overlay (beg end) 760 (defun viper-set-replace-overlay (beg end)
761 (if (viper-overlay-live-p viper-replace-overlay) 761 (if (viper-overlay-live-p viper-replace-overlay)
762 (viper-move-replace-overlay beg end) 762 (viper-move-replace-overlay beg end)
763 (setq viper-replace-overlay (viper-make-overlay beg end (current-buffer))) 763 (setq viper-replace-overlay (viper-make-overlay beg end (current-buffer)))
764 ;; never detach 764 ;; never detach
765 (viper-overlay-put 765 (viper-overlay-put
766 viper-replace-overlay (if viper-emacs-p 'evaporate 'detachable) nil) 766 viper-replace-overlay (if viper-emacs-p 'evaporate 'detachable) nil)
767 (viper-overlay-put 767 (viper-overlay-put
768 viper-replace-overlay 'priority viper-replace-overlay-priority) 768 viper-replace-overlay 'priority viper-replace-overlay-priority)
769 ;; If Emacs will start supporting overlay maps, as it currently supports 769 ;; If Emacs will start supporting overlay maps, as it currently supports
770 ;; text-property maps, we could do away with viper-replace-minor-mode and 770 ;; text-property maps, we could do away with viper-replace-minor-mode and
771 ;; just have keymap attached to replace overlay. 771 ;; just have keymap attached to replace overlay.
772 ;;(viper-overlay-put 772 ;;(viper-overlay-put
773 ;; viper-replace-overlay 773 ;; viper-replace-overlay
774 ;; (if viper-xemacs-p 'keymap 'local-map) 774 ;; (if viper-xemacs-p 'keymap 'local-map)
775 ;; viper-replace-map) 775 ;; viper-replace-map)
776 ) 776 )
777 (if (viper-has-face-support-p) 777 (if (viper-has-face-support-p)
778 (viper-overlay-put 778 (viper-overlay-put
779 viper-replace-overlay 'face viper-replace-overlay-face)) 779 viper-replace-overlay 'face viper-replace-overlay-face))
780 (viper-save-cursor-color 'before-replace-mode) 780 (viper-save-cursor-color 'before-replace-mode)
781 (viper-change-cursor-color viper-replace-overlay-cursor-color) 781 (viper-change-cursor-color viper-replace-overlay-cursor-color)
782 ) 782 )
783 783
784 784
785 (defun viper-set-replace-overlay-glyphs (before-glyph after-glyph) 785 (defun viper-set-replace-overlay-glyphs (before-glyph after-glyph)
786 (or (viper-overlay-live-p viper-replace-overlay) 786 (or (viper-overlay-live-p viper-replace-overlay)
787 (viper-set-replace-overlay (point-min) (point-min))) 787 (viper-set-replace-overlay (point-min) (point-min)))
788 (if (or (not (viper-has-face-support-p)) 788 (if (or (not (viper-has-face-support-p))
789 viper-use-replace-region-delimiters) 789 viper-use-replace-region-delimiters)
790 (let ((before-name (if viper-xemacs-p 'begin-glyph 'before-string)) 790 (let ((before-name (if viper-xemacs-p 'begin-glyph 'before-string))
791 (after-name (if viper-xemacs-p 'end-glyph 'after-string))) 791 (after-name (if viper-xemacs-p 'end-glyph 'after-string)))
792 (viper-overlay-put viper-replace-overlay before-name before-glyph) 792 (viper-overlay-put viper-replace-overlay before-name before-glyph)
793 (viper-overlay-put viper-replace-overlay after-name after-glyph)))) 793 (viper-overlay-put viper-replace-overlay after-name after-glyph))))
794 794
795 (defun viper-hide-replace-overlay () 795 (defun viper-hide-replace-overlay ()
796 (viper-set-replace-overlay-glyphs nil nil) 796 (viper-set-replace-overlay-glyphs nil nil)
797 (viper-restore-cursor-color 'after-replace-mode) 797 (viper-restore-cursor-color 'after-replace-mode)
798 (viper-restore-cursor-color 'after-insert-mode) 798 (viper-restore-cursor-color 'after-insert-mode)
799 (if (viper-has-face-support-p) 799 (if (viper-has-face-support-p)
800 (viper-overlay-put viper-replace-overlay 'face nil))) 800 (viper-overlay-put viper-replace-overlay 'face nil)))
801 801
802 802
803 (defsubst viper-replace-start () 803 (defsubst viper-replace-start ()
804 (viper-overlay-start viper-replace-overlay)) 804 (viper-overlay-start viper-replace-overlay))
805 (defsubst viper-replace-end () 805 (defsubst viper-replace-end ()
806 (viper-overlay-end viper-replace-overlay)) 806 (viper-overlay-end viper-replace-overlay))
807 807
808 808
809 ;; Minibuffer 809 ;; Minibuffer
810 810
811 (defun viper-set-minibuffer-overlay () 811 (defun viper-set-minibuffer-overlay ()
812 (viper-check-minibuffer-overlay) 812 (viper-check-minibuffer-overlay)
813 (if (viper-has-face-support-p) 813 (if (viper-has-face-support-p)
814 (progn 814 (progn
815 (viper-overlay-put 815 (viper-overlay-put
816 viper-minibuffer-overlay 'face viper-minibuffer-current-face) 816 viper-minibuffer-overlay 'face viper-minibuffer-current-face)
817 (viper-overlay-put 817 (viper-overlay-put
818 viper-minibuffer-overlay 'priority viper-minibuffer-overlay-priority) 818 viper-minibuffer-overlay 'priority viper-minibuffer-overlay-priority)
819 ;; never detach 819 ;; never detach
820 (viper-overlay-put 820 (viper-overlay-put
821 viper-minibuffer-overlay 821 viper-minibuffer-overlay
822 (if viper-emacs-p 'evaporate 'detachable) 822 (if viper-emacs-p 'evaporate 'detachable)
826 (if viper-xemacs-p 826 (if viper-xemacs-p
827 (progn 827 (progn
828 (viper-overlay-put viper-minibuffer-overlay 'start-open nil) 828 (viper-overlay-put viper-minibuffer-overlay 'start-open nil)
829 (viper-overlay-put viper-minibuffer-overlay 'end-open nil))) 829 (viper-overlay-put viper-minibuffer-overlay 'end-open nil)))
830 ))) 830 )))
831 831
832 (defun viper-check-minibuffer-overlay () 832 (defun viper-check-minibuffer-overlay ()
833 (if (viper-overlay-live-p viper-minibuffer-overlay) 833 (if (viper-overlay-live-p viper-minibuffer-overlay)
834 (viper-move-overlay 834 (viper-move-overlay
835 viper-minibuffer-overlay 835 viper-minibuffer-overlay
836 (if (fboundp 'minibuffer-prompt-end) (minibuffer-prompt-end) 1) 836 (if (fboundp 'minibuffer-prompt-end) (minibuffer-prompt-end) 1)
847 847
848 848
849 (defsubst viper-is-in-minibuffer () 849 (defsubst viper-is-in-minibuffer ()
850 (save-match-data 850 (save-match-data
851 (string-match "\*Minibuf-" (buffer-name)))) 851 (string-match "\*Minibuf-" (buffer-name))))
852 852
853 853
854 854
855 ;;; XEmacs compatibility 855 ;;; XEmacs compatibility
856 856
857 (defun viper-abbreviate-file-name (file) 857 (defun viper-abbreviate-file-name (file)
859 ;; XEmacs requires addl argument 859 ;; XEmacs requires addl argument
860 (abbreviate-file-name file t) 860 (abbreviate-file-name file t)
861 ;; emacs 861 ;; emacs
862 (abbreviate-file-name file) 862 (abbreviate-file-name file)
863 )) 863 ))
864 864
865 ;; Sit for VAL milliseconds. XEmacs doesn't support the millisecond arg 865 ;; Sit for VAL milliseconds. XEmacs doesn't support the millisecond arg
866 ;; in sit-for, so this function smoothes out the differences. 866 ;; in sit-for, so this function smoothes out the differences.
867 (defsubst viper-sit-for-short (val &optional nodisp) 867 (defsubst viper-sit-for-short (val &optional nodisp)
868 (if viper-xemacs-p 868 (if viper-xemacs-p
869 (sit-for (/ val 1000.0) nodisp) 869 (sit-for (/ val 1000.0) nodisp)
870 (sit-for 0 val nodisp))) 870 (sit-for 0 val nodisp)))
881 (let ((buf (marker-buffer marker)) 881 (let ((buf (marker-buffer marker))
882 (pos (marker-position marker))) 882 (pos (marker-position marker)))
883 (save-excursion 883 (save-excursion
884 (set-buffer buf) 884 (set-buffer buf)
885 (and (<= pos (point-max)) (<= (point-min) pos)))))) 885 (and (<= pos (point-max)) (<= (point-min) pos))))))
886 886
887 (defsubst viper-mark-marker () 887 (defsubst viper-mark-marker ()
888 (viper-cond-compile-for-xemacs-or-emacs 888 (viper-cond-compile-for-xemacs-or-emacs
889 (mark-marker t) ; xemacs 889 (mark-marker t) ; xemacs
890 (mark-marker) ; emacs 890 (mark-marker) ; emacs
891 )) 891 ))
894 ;; is the same as (mark t). 894 ;; is the same as (mark t).
895 (defsubst viper-set-mark-if-necessary () 895 (defsubst viper-set-mark-if-necessary ()
896 (setq mark-ring (delete (viper-mark-marker) mark-ring)) 896 (setq mark-ring (delete (viper-mark-marker) mark-ring))
897 (set-mark-command nil) 897 (set-mark-command nil)
898 (setq viper-saved-mark (point))) 898 (setq viper-saved-mark (point)))
899 899
900 ;; In transient mark mode (zmacs mode), it is annoying when regions become 900 ;; In transient mark mode (zmacs mode), it is annoying when regions become
901 ;; highlighted due to Viper's pushing marks. So, we deactivate marks, unless 901 ;; highlighted due to Viper's pushing marks. So, we deactivate marks, unless
902 ;; the user explicitly wants highlighting, e.g., by hitting '' or `` 902 ;; the user explicitly wants highlighting, e.g., by hitting '' or ``
903 (defun viper-deactivate-mark () 903 (defun viper-deactivate-mark ()
904 (viper-cond-compile-for-xemacs-or-emacs 904 (viper-cond-compile-for-xemacs-or-emacs
925 (and (<= ?1 reg) (<= reg ?9))) 925 (and (<= ?1 reg) (<= reg ?9)))
926 (if (memq 'Letter type) 926 (if (memq 'Letter type)
927 (and (<= ?A reg) (<= reg ?Z))) 927 (and (<= ?A reg) (<= reg ?Z)))
928 )) 928 ))
929 929
930 930
931 931
932 ;; it is suggested that an event must be copied before it is assigned to 932 ;; it is suggested that an event must be copied before it is assigned to
933 ;; last-command-event in XEmacs 933 ;; last-command-event in XEmacs
934 (defun viper-copy-event (event) 934 (defun viper-copy-event (event)
935 (viper-cond-compile-for-xemacs-or-emacs 935 (viper-cond-compile-for-xemacs-or-emacs
936 (copy-event event) ; xemacs 936 (copy-event event) ; xemacs
937 event ; emacs 937 event ; emacs
938 )) 938 ))
939 939
940 ;; Uses different timeouts for ESC-sequences and others 940 ;; Uses different timeouts for ESC-sequences and others
941 (defsubst viper-fast-keysequence-p () 941 (defsubst viper-fast-keysequence-p ()
942 (not (viper-sit-for-short 942 (not (viper-sit-for-short
943 (if (viper-ESC-event-p last-input-event) 943 (if (viper-ESC-event-p last-input-event)
944 viper-ESC-keyseq-timeout 944 viper-ESC-keyseq-timeout
945 viper-fast-keyseq-timeout) 945 viper-fast-keyseq-timeout)
946 t))) 946 t)))
947 947
948 ;; like read-event, but in XEmacs also try to convert to char, if possible 948 ;; like read-event, but in XEmacs also try to convert to char, if possible
949 (defun viper-read-event-convert-to-char () 949 (defun viper-read-event-convert-to-char ()
950 (let (event) 950 (let (event)
951 (viper-cond-compile-for-xemacs-or-emacs 951 (viper-cond-compile-for-xemacs-or-emacs
952 (progn 952 (progn
976 (viper-insert-local-user-minor-mode nil)) 976 (viper-insert-local-user-minor-mode nil))
977 ;; Note: set unread-command-events only after testing for fast 977 ;; Note: set unread-command-events only after testing for fast
978 ;; keysequence. Otherwise, viper-fast-keysequence-p will be 978 ;; keysequence. Otherwise, viper-fast-keysequence-p will be
979 ;; always t -- whether there is anything after ESC or not 979 ;; always t -- whether there is anything after ESC or not
980 (viper-set-unread-command-events keyseq) 980 (viper-set-unread-command-events keyseq)
981 (setq keyseq (read-key-sequence nil))) 981 (setq keyseq (read-key-sequence nil)))
982 (viper-set-unread-command-events keyseq) 982 (viper-set-unread-command-events keyseq)
983 (setq keyseq (read-key-sequence nil))))) 983 (setq keyseq (read-key-sequence nil)))))
984 keyseq)) 984 keyseq))
985 985
986 986
987 ;; This function lets function-key-map convert key sequences into logical 987 ;; This function lets function-key-map convert key sequences into logical
988 ;; keys. This does a better job than viper-read-event when it comes to kbd 988 ;; keys. This does a better job than viper-read-event when it comes to kbd
989 ;; macros, since it enables certain macros to be shared between X and TTY modes 989 ;; macros, since it enables certain macros to be shared between X and TTY modes
990 ;; by correctly mapping key sequences for Left/Right/... (one an ascii 990 ;; by correctly mapping key sequences for Left/Right/... (one an ascii
991 ;; terminal) into logical keys left, right, etc. 991 ;; terminal) into logical keys left, right, etc.
992 (defun viper-read-key () 992 (defun viper-read-key ()
993 (let ((overriding-local-map viper-overriding-map) 993 (let ((overriding-local-map viper-overriding-map)
994 (inhibit-quit t) 994 (inhibit-quit t)
995 help-char key) 995 help-char key)
996 (use-global-map viper-overriding-map) 996 (use-global-map viper-overriding-map)
997 (unwind-protect 997 (unwind-protect
998 (setq key (elt (viper-read-key-sequence nil) 0)) 998 (setq key (elt (viper-read-key-sequence nil) 0))
999 (use-global-map global-map)) 999 (use-global-map global-map))
1000 key)) 1000 key))
1001 1001
1002 1002
1003 ;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil) 1003 ;; Emacs has a bug in eventp, which causes (eventp nil) to return (nil)
1017 ;; XEmacs 1017 ;; XEmacs
1018 (cond ((key-press-event-p event) 1018 (cond ((key-press-event-p event)
1019 (event-key event)) 1019 (event-key event))
1020 ((button-event-p event) 1020 ((button-event-p event)
1021 (concat "mouse-" (prin1-to-string (event-button event)))) 1021 (concat "mouse-" (prin1-to-string (event-button event))))
1022 (t 1022 (t
1023 (error "viper-event-key: Unknown event, %S" event))) 1023 (error "viper-event-key: Unknown event, %S" event)))
1024 ;; Emacs doesn't handle capital letters correctly, since 1024 ;; Emacs doesn't handle capital letters correctly, since
1025 ;; \S-a isn't considered the same as A (it behaves as 1025 ;; \S-a isn't considered the same as A (it behaves as
1026 ;; plain `a' instead). So we take care of this here 1026 ;; plain `a' instead). So we take care of this here
1027 (cond ((and (viper-characterp event) (<= ?A event) (<= event ?Z)) 1027 (cond ((and (viper-characterp event) (<= ?A event) (<= event ?Z))
1051 (list 'control '\?) ; taking care of an emacs bug 1051 (list 'control '\?) ; taking care of an emacs bug
1052 (intern (char-to-string basis))))) 1052 (intern (char-to-string basis)))))
1053 (if mod 1053 (if mod
1054 (append mod (list basis)) 1054 (append mod (list basis))
1055 basis)))) 1055 basis))))
1056 1056
1057 (defun viper-key-to-emacs-key (key) 1057 (defun viper-key-to-emacs-key (key)
1058 (let (key-name char-p modifiers mod-char-list base-key base-key-name) 1058 (let (key-name char-p modifiers mod-char-list base-key base-key-name)
1059 (cond (viper-xemacs-p key) 1059 (cond (viper-xemacs-p key)
1060 1060
1061 ((symbolp key) 1061 ((symbolp key)
1107 ((eventp elt) elt) 1107 ((eventp elt) elt)
1108 (t (error 1108 (t (error
1109 "viper-eventify-list-xemacs: can't convert to event, %S" 1109 "viper-eventify-list-xemacs: can't convert to event, %S"
1110 elt)))) 1110 elt))))
1111 lis)) 1111 lis))
1112 1112
1113 1113
1114 ;; Smoothes out the difference between Emacs' unread-command-events 1114 ;; Smoothes out the difference between Emacs' unread-command-events
1115 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of 1115 ;; and XEmacs unread-command-event. Arg is a character, an event, a list of
1116 ;; events or a sequence of keys. 1116 ;; events or a sequence of keys.
1117 ;; 1117 ;;
1152 ;; XEmacs only 1152 ;; XEmacs only
1153 (defun viper-event-vector-p (vec) 1153 (defun viper-event-vector-p (vec)
1154 (and (vectorp vec) 1154 (and (vectorp vec)
1155 (eval (cons 'and (mapcar '(lambda (elt) (if (eventp elt) t)) vec))))) 1155 (eval (cons 'and (mapcar '(lambda (elt) (if (eventp elt) t)) vec)))))
1156 1156
1157 1157
1158 ;; check if vec is a vector of character symbols 1158 ;; check if vec is a vector of character symbols
1159 (defun viper-char-symbol-sequence-p (vec) 1159 (defun viper-char-symbol-sequence-p (vec)
1160 (and 1160 (and
1161 (sequencep vec) 1161 (sequencep vec)
1162 (eval 1162 (eval
1163 (cons 'and 1163 (cons 'and
1164 (mapcar (lambda (elt) 1164 (mapcar (lambda (elt)
1165 (and (symbolp elt) (= (length (symbol-name elt)) 1))) 1165 (and (symbolp elt) (= (length (symbol-name elt)) 1)))
1166 vec))))) 1166 vec)))))
1167 1167
1168 1168
1169 (defun viper-char-array-p (array) 1169 (defun viper-char-array-p (array)
1170 (eval (cons 'and (mapcar 'viper-characterp array)))) 1170 (eval (cons 'and (mapcar 'viper-characterp array))))
1171 1171
1172 1172
1173 ;; Args can be a sequence of events, a string, or a Viper macro. Will try to 1173 ;; Args can be a sequence of events, a string, or a Viper macro. Will try to
1186 (setq temp2 (mapcar 'viper-key-to-character temp)))) 1186 (setq temp2 (mapcar 'viper-key-to-character temp))))
1187 (mapconcat 'char-to-string temp2 "")) 1187 (mapconcat 'char-to-string temp2 ""))
1188 (t (prin1-to-string (vconcat temp))))) 1188 (t (prin1-to-string (vconcat temp)))))
1189 ((viper-char-symbol-sequence-p event-seq) 1189 ((viper-char-symbol-sequence-p event-seq)
1190 (mapconcat 'symbol-name event-seq "")) 1190 (mapconcat 'symbol-name event-seq ""))
1191 ((and (vectorp event-seq) 1191 ((and (vectorp event-seq)
1192 (viper-char-array-p 1192 (viper-char-array-p
1193 (setq temp (mapcar 'viper-key-to-character event-seq)))) 1193 (setq temp (mapcar 'viper-key-to-character event-seq))))
1194 (mapconcat 'char-to-string temp "")) 1194 (mapconcat 'char-to-string temp ""))
1195 (t (prin1-to-string event-seq))))) 1195 (t (prin1-to-string event-seq)))))
1196 1196
1199 (lambda (elt) (char-to-string (event-to-character elt))) ; xemacs 1199 (lambda (elt) (char-to-string (event-to-character elt))) ; xemacs
1200 'char-to-string ; emacs 1200 'char-to-string ; emacs
1201 ) 1201 )
1202 events 1202 events
1203 "")) 1203 ""))
1204 1204
1205 1205
1206 (defun viper-read-char-exclusive () 1206 (defun viper-read-char-exclusive ()
1207 (let (char 1207 (let (char
1208 (echo-keystrokes 1)) 1208 (echo-keystrokes 1))
1209 (while (null char) 1209 (while (null char)
1210 (condition-case nil 1210 (condition-case nil
1228 (eq (car key) 'control) 1228 (eq (car key) 'control)
1229 (symbol-name (nth 1 key)) 1229 (symbol-name (nth 1 key))
1230 (= 1 (length (symbol-name (nth 1 key))))) 1230 (= 1 (length (symbol-name (nth 1 key)))))
1231 (read (format "?\\C-%s" (symbol-name (nth 1 key))))) 1231 (read (format "?\\C-%s" (symbol-name (nth 1 key)))))
1232 (t key))) 1232 (t key)))
1233 1233
1234 1234
1235 (defun viper-setup-master-buffer (&rest other-files-or-buffers) 1235 (defun viper-setup-master-buffer (&rest other-files-or-buffers)
1236 "Set up the current buffer as a master buffer. 1236 "Set up the current buffer as a master buffer.
1237 Arguments become related buffers. This function should normally be used in 1237 Arguments become related buffers. This function should normally be used in
1238 the `Local variables' section of a file." 1238 the `Local variables' section of a file."
1239 (setq viper-related-files-and-buffers-ring 1239 (setq viper-related-files-and-buffers-ring
1240 (make-ring (1+ (length other-files-or-buffers)))) 1240 (make-ring (1+ (length other-files-or-buffers))))
1241 (mapcar '(lambda (elt) 1241 (mapcar '(lambda (elt)
1242 (viper-ring-insert viper-related-files-and-buffers-ring elt)) 1242 (viper-ring-insert viper-related-files-and-buffers-ring elt))
1243 other-files-or-buffers) 1243 other-files-or-buffers)
1244 (viper-ring-insert viper-related-files-and-buffers-ring (buffer-name)) 1244 (viper-ring-insert viper-related-files-and-buffers-ring (buffer-name))
1275 "String of syntax classes for Vi separators. 1275 "String of syntax classes for Vi separators.
1276 Usually contains ` ', linefeed, TAB or formfeed.") 1276 Usually contains ` ', linefeed, TAB or formfeed.")
1277 1277
1278 1278
1279 ;; Set Viper syntax classes and related variables according to 1279 ;; Set Viper syntax classes and related variables according to
1280 ;; `viper-syntax-preference'. 1280 ;; `viper-syntax-preference'.
1281 (defun viper-update-syntax-classes (&optional set-default) 1281 (defun viper-update-syntax-classes (&optional set-default)
1282 (let ((preference (cond ((eq viper-syntax-preference 'emacs) 1282 (let ((preference (cond ((eq viper-syntax-preference 'emacs)
1283 "w") ; Viper words have only Emacs word chars 1283 "w") ; Viper words have only Emacs word chars
1284 ((eq viper-syntax-preference 'extended) 1284 ((eq viper-syntax-preference 'extended)
1285 "w_") ; Viper words have Emacs word & symbol chars 1285 "w_") ; Viper words have Emacs word & symbol chars
1336 This is most appropriate for major modes intended for editing programs. 1336 This is most appropriate for major modes intended for editing programs.
1337 1337
1338 `emacs' means Viper words are the same as Emacs words as specified by Emacs 1338 `emacs' means Viper words are the same as Emacs words as specified by Emacs
1339 syntax tables. 1339 syntax tables.
1340 This option is appropriate if you like Emacs-style words." 1340 This option is appropriate if you like Emacs-style words."
1341 :type '(radio (const strict-vi) (const reformed-vi) 1341 :type '(radio (const strict-vi) (const reformed-vi)
1342 (const extended) (const emacs)) 1342 (const extended) (const emacs))
1343 :set 'viper-set-syntax-preference 1343 :set 'viper-set-syntax-preference
1344 :group 'viper) 1344 :group 'viper)
1345 (make-variable-buffer-local 'viper-syntax-preference) 1345 (make-variable-buffer-local 'viper-syntax-preference)
1346 1346
1380 (or (viper-looking-at-separator) (viper-looking-at-alpha addl-chars))) 1380 (or (viper-looking-at-separator) (viper-looking-at-alpha addl-chars)))
1381 1381
1382 (defun viper-skip-alpha-forward (&optional addl-chars) 1382 (defun viper-skip-alpha-forward (&optional addl-chars)
1383 (or (stringp addl-chars) (setq addl-chars "")) 1383 (or (stringp addl-chars) (setq addl-chars ""))
1384 (viper-skip-syntax 1384 (viper-skip-syntax
1385 'forward 1385 'forward
1386 (cond ((eq viper-syntax-preference 'strict-vi) 1386 (cond ((eq viper-syntax-preference 'strict-vi)
1387 "") 1387 "")
1388 (t viper-ALPHA-char-class)) 1388 (t viper-ALPHA-char-class))
1389 (cond ((eq viper-syntax-preference 'strict-vi) 1389 (cond ((eq viper-syntax-preference 'strict-vi)
1390 (concat viper-strict-ALPHA-chars addl-chars)) 1390 (concat viper-strict-ALPHA-chars addl-chars))
1391 (t addl-chars)))) 1391 (t addl-chars))))
1392 1392
1393 (defun viper-skip-alpha-backward (&optional addl-chars) 1393 (defun viper-skip-alpha-backward (&optional addl-chars)
1394 (or (stringp addl-chars) (setq addl-chars "")) 1394 (or (stringp addl-chars) (setq addl-chars ""))
1395 (viper-skip-syntax 1395 (viper-skip-syntax
1396 'backward 1396 'backward
1397 (cond ((eq viper-syntax-preference 'strict-vi) 1397 (cond ((eq viper-syntax-preference 'strict-vi)
1398 "") 1398 "")
1399 (t viper-ALPHA-char-class)) 1399 (t viper-ALPHA-char-class))
1400 (cond ((eq viper-syntax-preference 'strict-vi) 1400 (cond ((eq viper-syntax-preference 'strict-vi)
1401 (concat viper-strict-ALPHA-chars addl-chars)) 1401 (concat viper-strict-ALPHA-chars addl-chars))
1402 (t addl-chars)))) 1402 (t addl-chars))))
1403 1403
1404 ;; weird syntax tables may confuse strict-vi style 1404 ;; weird syntax tables may confuse strict-vi style
1405 (defsubst viper-skip-all-separators-forward (&optional within-line) 1405 (defsubst viper-skip-all-separators-forward (&optional within-line)
1406 (if (eq viper-syntax-preference 'strict-vi) 1406 (if (eq viper-syntax-preference 'strict-vi)
1407 (if within-line 1407 (if within-line
1408 (skip-chars-forward viper-strict-SEP-chars-sans-newline) 1408 (skip-chars-forward viper-strict-SEP-chars-sans-newline)
1409 (skip-chars-forward viper-strict-SEP-chars)) 1409 (skip-chars-forward viper-strict-SEP-chars))
1410 (viper-skip-syntax 'forward 1410 (viper-skip-syntax 'forward
1411 viper-SEP-char-class 1411 viper-SEP-char-class
1412 (or within-line "\n") 1412 (or within-line "\n")
1413 (if within-line (viper-line-pos 'end))))) 1413 (if within-line (viper-line-pos 'end)))))
1414 (defsubst viper-skip-all-separators-backward (&optional within-line) 1414 (defsubst viper-skip-all-separators-backward (&optional within-line)
1415 (if (eq viper-syntax-preference 'strict-vi) 1415 (if (eq viper-syntax-preference 'strict-vi)
1416 (if within-line 1416 (if within-line
1417 (skip-chars-backward viper-strict-SEP-chars-sans-newline) 1417 (skip-chars-backward viper-strict-SEP-chars-sans-newline)
1418 (skip-chars-backward viper-strict-SEP-chars)) 1418 (skip-chars-backward viper-strict-SEP-chars))
1419 (viper-skip-syntax 'backward 1419 (viper-skip-syntax 'backward
1420 viper-SEP-char-class 1420 viper-SEP-char-class
1421 (or within-line "\n") 1421 (or within-line "\n")
1435 (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars)) 1435 (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars))
1436 (viper-skip-syntax 1436 (viper-skip-syntax
1437 'forward 1437 'forward
1438 (concat "^" viper-ALPHA-char-class viper-SEP-char-class) 1438 (concat "^" viper-ALPHA-char-class viper-SEP-char-class)
1439 ;; Emacs may consider some of these as words, but we don't want them 1439 ;; Emacs may consider some of these as words, but we don't want them
1440 viper-non-word-characters 1440 viper-non-word-characters
1441 (viper-line-pos 'end)))) 1441 (viper-line-pos 'end))))
1442 (defun viper-skip-nonalphasep-backward () 1442 (defun viper-skip-nonalphasep-backward ()
1443 (if (eq viper-syntax-preference 'strict-vi) 1443 (if (eq viper-syntax-preference 'strict-vi)
1444 (skip-chars-backward 1444 (skip-chars-backward
1445 (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars)) 1445 (concat "^" viper-strict-SEP-chars viper-strict-ALPHA-chars))
1473 (cond ((listp syntax) syntax) 1473 (cond ((listp syntax) syntax)
1474 ((stringp syntax) (viper-string-to-list syntax)) 1474 ((stringp syntax) (viper-string-to-list syntax))
1475 (t nil))) 1475 (t nil)))
1476 (if (memq ?^ syntax) (setq negated-syntax t)) 1476 (if (memq ?^ syntax) (setq negated-syntax t))
1477 1477
1478 (while (and (not (= local 0)) 1478 (while (and (not (= local 0))
1479 (cond ((eq direction 'forward) 1479 (cond ((eq direction 'forward)
1480 (not (eobp))) 1480 (not (eobp)))
1481 (t (not (bobp))))) 1481 (t (not (bobp)))))
1482 (setq char-looked-at (viper-char-at-pos direction) 1482 (setq char-looked-at (viper-char-at-pos direction)
1483 ;; if outside the range, set to nil 1483 ;; if outside the range, set to nil
1484 syntax-of-char-looked-at (if char-looked-at 1484 syntax-of-char-looked-at (if char-looked-at
1505 0) 1505 0)
1506 (funcall skip-chars-func addl-chars limit))) 1506 (funcall skip-chars-func addl-chars limit)))
1507 (setq total (+ total local))) 1507 (setq total (+ total local)))
1508 total 1508 total
1509 )) 1509 ))
1510 1510
1511 1511
1512 1512
1513 (provide 'viper-util) 1513 (provide 'viper-util)
1514 1514
1515 1515
1516 ;;; Local Variables: 1516 ;;; Local Variables:
1517 ;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun) 1517 ;;; eval: (put 'viper-deflocalvar 'lisp-indent-hook 'defun)
1518 ;;; End: 1518 ;;; End:
1519 1519