Function: mpc-select-extend

mpc-select-extend is an interactive and byte-compiled function defined in mpc.el.gz.

Signature

(mpc-select-extend &optional EVENT)

Documentation

Extend the selection up to point.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/mpc.el.gz
(defun mpc-select-extend (&optional event)
  "Extend the selection up to point."
  (interactive (list last-nonmenu-event))
  (mpc-event-set-point event)
  (if (null mpc-select)
      ;; If nothing's selected yet, fallback to selecting the elem at point.
      (mpc-select event)
    (save-excursion
      (cond
       ;; The line is already in a selected area; truncate the area.
       ((get-char-property (point) 'mpc-select)
        (let ((before 0)
              (after 0)
              (mid (line-beginning-position))
              start end)
          (while (and (zerop (forward-line 1))
                      (get-char-property (point) 'mpc-select))
            (setq end (1+ (point)))
            (cl-incf after))
          (goto-char mid)
          (while (and (zerop (forward-line -1))
                      (get-char-property (point) 'mpc-select))
            (setq start (point))
            (cl-incf before))
          (if (and (= after 0) (= before 0))
              ;; Shortening an already minimum-size region: do nothing.
              nil
            (if (> after before)
                (setq end mid)
              (setq start (1+ mid)))
            (let ((ols '()))
              (dolist (ol mpc-select)
                (if (and (>= (overlay-start ol) start)
                         (< (overlay-start ol) end))
                    (delete-overlay ol)
                  (push ol ols)))
              (setq mpc-select (nreverse ols))))))
       ;; Extending a prior area.  Look for the closest selection.
       (t
        (when (mpc-tagbrowser-all-p)
          (forward-line 1))
        (let ((before 0)
              (count 0)
              (dir 1)
              (start (line-beginning-position)))
          (while (and (zerop (forward-line 1))
                      (not (get-char-property (point) 'mpc-select)))
            (cl-incf count))
          (unless (get-char-property (point) 'mpc-select)
            (setq count nil))
          (goto-char start)
          (while (and (zerop (forward-line -1))
                      (not (get-char-property (point) 'mpc-select)))
            (cl-incf before))
          (unless (get-char-property (point) 'mpc-select)
            (setq before nil))
          (when (and before (or (null count) (< before count)))
            (setq count before)
            (setq dir -1))
          (goto-char start)
          (dotimes (_i (1+ (or count 0)))
            (mpc-select-make-overlay)
            (forward-line dir))))))
    (when mpc-tag
      (mpc-tagbrowser-all-select)
      (mpc-selection-refresh))))