aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/dabbrev.el101
1 files changed, 76 insertions, 25 deletions
diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el
index 2d14fbb07e7..d57ba974363 100644
--- a/lisp/dabbrev.el
+++ b/lisp/dabbrev.el
@@ -433,22 +433,57 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
433 (setq abbrev dabbrev--last-abbreviation) 433 (setq abbrev dabbrev--last-abbreviation)
434 (setq old dabbrev--last-expansion) 434 (setq old dabbrev--last-expansion)
435 (setq direction dabbrev--last-direction)) 435 (setq direction dabbrev--last-direction))
436 ;; We have a different abbrev to expand. 436 ;; If the user inserts a space after expanding
437 (dabbrev--reset-global-variables) 437 ;; and then asks to expand again, always fetch the next word.
438 (setq direction (if (null arg) 438 (if (and (eq (preceding-char) ?\ )
439 (if dabbrev-backward-only 1 0) 439 (markerp dabbrev--last-abbrev-location)
440 (prefix-numeric-value arg))) 440 (marker-position dabbrev--last-abbrev-location)
441 (setq abbrev (dabbrev--abbrev-at-point)) 441 (= (point) (1+ dabbrev--last-abbrev-location)))
442 (setq old nil)) 442 (progn
443 ;; The "abbrev" to expand is just the space.
444 (setq abbrev " ")
445 (save-excursion
446 (if dabbrev--last-buffer
447 (set-buffer dabbrev--last-buffer))
448 ;; Find the end of the last "expansion" word.
449 (if (or (eq dabbrev--last-direction 1)
450 (and (eq dabbrev--last-direction 0)
451 (< dabbrev--last-expansion-location (point))))
452 (setq dabbrev--last-expansion-location
453 (+ dabbrev--last-expansion-location
454 (length dabbrev--last-expansion))))
455 (goto-char dabbrev--last-expansion-location)
456 ;; Take the following word, with intermediate separators,
457 ;; as our expansion this time.
458 (re-search-forward
459 (concat "\\(\\(" dabbrev--abbrev-char-regexp "\\)+\\)"))
460 (setq expansion
461 (buffer-substring dabbrev--last-expansion-location
462 (point)))
463
464 ;; Record the end of this expansion, in case we repeat this.
465 (setq dabbrev--last-expansion-location (point)))
466 ;; Indicate that dabbrev--last-expansion-location is
467 ;; at the end of the expansion.
468 (setq dabbrev--last-direction -1))
469
470 ;; We have a different abbrev to expand.
471 (dabbrev--reset-global-variables)
472 (setq direction (if (null arg)
473 (if dabbrev-backward-only 1 0)
474 (prefix-numeric-value arg)))
475 (setq abbrev (dabbrev--abbrev-at-point))
476 (setq old nil)))
443 477
444 ;;-------------------------------- 478 ;;--------------------------------
445 ;; Find the expansion 479 ;; Find the expansion
446 ;;-------------------------------- 480 ;;--------------------------------
447 (setq expansion 481 (or expansion
448 (dabbrev--find-expansion abbrev direction 482 (setq expansion
449 (and (eval dabbrev-case-fold-search) 483 (dabbrev--find-expansion abbrev direction
450 (or (not dabbrev-upcase-means-case-search) 484 (and (eval dabbrev-case-fold-search)
451 (string= abbrev (downcase abbrev))))))) 485 (or (not dabbrev-upcase-means-case-search)
486 (string= abbrev (downcase abbrev))))))))
452 (cond 487 (cond
453 ((not expansion) 488 ((not expansion)
454 (dabbrev--reset-global-variables) 489 (dabbrev--reset-global-variables)
@@ -465,6 +500,12 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
465 (buffer-name dabbrev--last-buffer)) 500 (buffer-name dabbrev--last-buffer))
466 (setq dabbrev--last-buffer-found dabbrev--last-buffer)) 501 (setq dabbrev--last-buffer-found dabbrev--last-buffer))
467 (message nil)) 502 (message nil))
503 (if (and (or (eq (current-buffer) dabbrev--last-buffer)
504 (null dabbrev--last-buffer))
505 (numberp dabbrev--last-expansion-location)
506 (and (> dabbrev--last-expansion-location (point))))
507 (setq dabbrev--last-expansion-location
508 (copy-marker dabbrev--last-expansion-location)))
468 ;; Success: stick it in and return. 509 ;; Success: stick it in and return.
469 (dabbrev--substitute-expansion old abbrev expansion) 510 (dabbrev--substitute-expansion old abbrev expansion)
470 ;; Save state for re-expand. 511 ;; Save state for re-expand.
@@ -505,22 +546,32 @@ See also `dabbrev-abbrev-char-regexp' and \\[dabbrev-completion]."
505;;; Extract the symbol at point to serve as abbreviation. 546;;; Extract the symbol at point to serve as abbreviation.
506(defun dabbrev--abbrev-at-point () 547(defun dabbrev--abbrev-at-point ()
507 ;; Check for error 548 ;; Check for error
508 (save-excursion 549 (if (bobp)
509 (save-match-data 550 (error "No possible abbreviation preceding point"))
510 (if (or (bobp)
511 (progn
512 (forward-char -1)
513 (not (looking-at (concat "\\("
514 (or dabbrev-abbrev-char-regexp
515 "\\sw\\|\\s_")
516 "\\)+")))))
517 (error "Not positioned immediately after an abbreviation"))))
518 ;; Return abbrev at point 551 ;; Return abbrev at point
519 (save-excursion 552 (save-excursion
553 ;; Record the end of the abbreviation.
520 (setq dabbrev--last-abbrev-location (point)) 554 (setq dabbrev--last-abbrev-location (point))
521 (buffer-substring (point) 555 ;; If we aren't right after an abbreviation,
522 (progn (dabbrev--goto-start-of-abbrev) 556 ;; move point back to just after one.
523 (point))))) 557 ;; This is so the user can get successive words
558 ;; by typing the punctuation followed by M-/.
559 (save-match-data
560 (if (save-excursion
561 (forward-char -1)
562 (not (looking-at (concat "\\("
563 (or dabbrev-abbrev-char-regexp
564 "\\sw\\|\\s_")
565 "\\)+"))))
566 (if (re-search-backward (or dabbrev-abbrev-char-regexp
567 "\\sw\\|\\s_")
568 nil t)
569 (forward-char 1)
570 (error "No possible abbreviation preceding point"))))
571 ;; Now find the beginning of that one.
572 (dabbrev--goto-start-of-abbrev)
573 (buffer-substring dabbrev--last-abbrev-location
574 (point))))
524 575
525;;; Initializes all global variables 576;;; Initializes all global variables
526(defun dabbrev--reset-global-variables () 577(defun dabbrev--reset-global-variables ()