;; SYNOPSIS: Patches to override default behaviour of functions.
;; AUTHOR:   GPL(C) Mohsin Ahmed, http://www.cs.albany.edu/~mosh

;;; From isearch.el 28-Jan-96.

(defun isearch-yank-char ()
  "Pull next char from buffer into search string."
  (interactive)
  (isearch-yank 'char))

(defun isearch-yank (chunk)
  ;; Helper for isearch-yank-word and isearch-yank-line
  ;; CHUNK should be char, word, line or kill.
  (let ((string (cond
                 ((eq chunk 'kill)
                  (current-kill 0))
                 (t
                  (save-excursion
                    (and (not isearch-forward) isearch-other-end
                         (goto-char isearch-other-end))
                    (buffer-substring
                     (point)
                     (save-excursion
                       (cond
                        ((eq chunk 'char)  ;; mosh@sasi.com 98-10-12
                         (forward-char)
                        )
                        ((eq chunk 'word)
                         ; was (forward-word 1)
                         ; was (mosh-forward-word)
                         (mosh-move-word 1)  ;; Mohsin Ahmed mosh@sasi.com
                        )
                        ((eq chunk 'line)
                         (end-of-line)))
                       (point))))))))
    ;; Downcase the string if not supposed to case-fold yanked strings.
    (if (and isearch-case-fold-search
             (eq 'not-yanks search-upper-case))
        (setq string (downcase string)))
    (if isearch-regexp (setq string (regexp-quote string)))
    (setq isearch-string (concat isearch-string string)
          isearch-message
          (concat isearch-message
                  (mapconcat 'isearch-text-char-description
                             string ""))
          ;; Don't move cursor in reverse search.
          isearch-yank-flag t))
  (isearch-search-and-update))

;; =========================================================
;; Saves pos for C-x C-v same-file goes to same spot, MohsinA, 01-Feb-97.

(defun find-alternate-file (filename)
  "Find file FILENAME, select its buffer, kill previous buffer.
If the current buffer now contains an empty file that you just visited
\(presumably by mistake), use this command to visit the file you really want."
  (interactive
   (let ((file buffer-file-name)
	 (file-name nil)
	 (file-dir nil))
     (and file
	  (setq file-name (file-name-nondirectory file)
		file-dir (file-name-directory file)))
     (list (read-file-name
	    "Find alternate file: " file-dir nil nil file-name))))
  (and (buffer-modified-p) (buffer-file-name)
       ;; (not buffer-read-only)
       (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
				 (buffer-name))))
       (error "Aborted"))
  (save-place-to-alist) ;; MohsinA, 07-Aug-96.
  (let ((obuf (current-buffer))
	(ofile buffer-file-name)
	(onum buffer-file-number)
	(otrue buffer-file-truename)
	(oname (buffer-name)))
    (if (get-buffer " **lose**")
	(kill-buffer " **lose**"))
    (rename-buffer " **lose**")
    (setq buffer-file-name nil)
    (setq buffer-file-number nil)
    (setq buffer-file-truename nil)
    (unwind-protect
	(progn
	  (unlock-buffer)
	  (find-file filename))
      (cond ((eq obuf (current-buffer))
	     (setq buffer-file-name ofile)
	     (setq buffer-file-number onum)
	     (setq buffer-file-truename otrue)
	     (lock-buffer)
	     (rename-buffer oname))))
    (or (eq (current-buffer) obuf)
        (kill-buffer obuf))))

;; From lisp/gud.el, => in color, 1999-06-28 mohsin@verysys.com

(defun gud-display-line (true-file line)
  (let* ((last-nonmenu-event t)	 ; Prevent use of dialog box for questions.
	 (buffer
	  (save-excursion
	    (or (eq (current-buffer) gud-comint-buffer)
		(set-buffer gud-comint-buffer))
	    (gud-find-file true-file)))
	 (window (and buffer (or (get-buffer-window buffer)
				 (display-buffer buffer))))
	 (pos))
    (if buffer
	(progn
	  (save-excursion
	    (set-buffer buffer)
	    (save-restriction
	      (widen)
	      (goto-line line)
	      (setq pos (point))
	      (setq overlay-arrow-string "=>")
              (mosh-color-char 'bold) ;; 1999-06-28 mohsin@verysys.com
	      (or overlay-arrow-position
		  (setq overlay-arrow-position (make-marker)))
	      (set-marker overlay-arrow-position (point) (current-buffer)))
	    (cond ((or (< pos (point-min)) (> pos (point-max)))
		   (widen)
		   (goto-char pos))))
	  (set-window-point window overlay-arrow-position)))))

;; EOF

