diff options
| author | Dave Love | 2000-08-15 14:18:18 +0000 |
|---|---|---|
| committer | Dave Love | 2000-08-15 14:18:18 +0000 |
| commit | 98d775e56e04e155bc509e61f3152db53f7641b0 (patch) | |
| tree | 0877df2c19b8ffd2ed7d2044f25d769506664d47 | |
| parent | 8e5b2bfe48b3df33ca8513e43668b75ee7fc560a (diff) | |
| download | emacs-98d775e56e04e155bc509e61f3152db53f7641b0.tar.gz emacs-98d775e56e04e155bc509e61f3152db53f7641b0.zip | |
Doc fixes. Move provide to end.
(ff) <defgroup>: Add :link.
(ff-goto-click): Deleted.
(ff-mouse-find-other-file, ff-mouse-find-other-file-other-window):
Use mouse-set-point.
| -rw-r--r-- | lisp/find-file.el | 172 |
1 files changed, 79 insertions, 93 deletions
diff --git a/lisp/find-file.el b/lisp/find-file.el index ebed0b73044..d59f10d22bd 100644 --- a/lisp/find-file.el +++ b/lisp/find-file.el | |||
| @@ -26,8 +26,8 @@ | |||
| 26 | ;;; Commentary: | 26 | ;;; Commentary: |
| 27 | 27 | ||
| 28 | ;; PURPOSE: | 28 | ;; PURPOSE: |
| 29 | ;; This package features a function called ff-find-other-file, which performs | 29 | ;; This package features a function called ff-find-other-file, which performs |
| 30 | ;; the following function: | 30 | ;; the following function: |
| 31 | ;; | 31 | ;; |
| 32 | ;; When in a .c file, find the first corresponding .h file in a set | 32 | ;; When in a .c file, find the first corresponding .h file in a set |
| 33 | ;; of directories and display it, and vice-versa from the .h file. | 33 | ;; of directories and display it, and vice-versa from the .h file. |
| @@ -38,7 +38,7 @@ | |||
| 38 | ;; to find that file. | 38 | ;; to find that file. |
| 39 | ;; | 39 | ;; |
| 40 | ;; THE "OTHER FILE", or "corresponding file", generally has the same basename, | 40 | ;; THE "OTHER FILE", or "corresponding file", generally has the same basename, |
| 41 | ;; and just has a different extension as described by the ff-other-file-alist | 41 | ;; and just has a different extension as described by the ff-other-file-alist |
| 42 | ;; variable: | 42 | ;; variable: |
| 43 | ;; | 43 | ;; |
| 44 | ;; '(("\\.cc$" (".hh" ".h")) | 44 | ;; '(("\\.cc$" (".hh" ".h")) |
| @@ -60,8 +60,8 @@ | |||
| 60 | ;; '(("\\.cc$" cc-function) | 60 | ;; '(("\\.cc$" cc-function) |
| 61 | ;; ("\\.hh$" hh-function)) | 61 | ;; ("\\.hh$" hh-function)) |
| 62 | ;; | 62 | ;; |
| 63 | ;; These functions must return a list consisting of the possible names of the | 63 | ;; These functions must return a list consisting of the possible names of the |
| 64 | ;; corresponding file, with or without path. There is no real need for more | 64 | ;; corresponding file, with or without path. There is no real need for more |
| 65 | ;; than one function, and one could imagine the following value for cc-other- | 65 | ;; than one function, and one could imagine the following value for cc-other- |
| 66 | ;; file-alist: | 66 | ;; file-alist: |
| 67 | ;; | 67 | ;; |
| @@ -91,12 +91,12 @@ | |||
| 91 | ;; | 91 | ;; |
| 92 | ;; If the file was not found, ff-find-other-file will prompt you for where | 92 | ;; If the file was not found, ff-find-other-file will prompt you for where |
| 93 | ;; to create the new "corresponding file" (defaults to the current directory), | 93 | ;; to create the new "corresponding file" (defaults to the current directory), |
| 94 | ;; unless the variable ff-always-try-to-create is set to nil. | 94 | ;; unless the variable ff-always-try-to-create is set to nil. |
| 95 | ;; | 95 | ;; |
| 96 | ;; GIVEN AN ARGUMENT (with the ^U prefix), ff-find-other-file will get the | 96 | ;; GIVEN AN ARGUMENT (with the ^U prefix), ff-find-other-file will get the |
| 97 | ;; other file in another (the other?) window (see find-file-other-window and | 97 | ;; other file in another (the other?) window (see find-file-other-window and |
| 98 | ;; switch-to-buffer-other-window). This can be set on a more permanent basis | 98 | ;; switch-to-buffer-other-window). This can be set on a more permanent basis |
| 99 | ;; by setting ff-always-in-other-window to t in which case the ^U prefix will | 99 | ;; by setting ff-always-in-other-window to t in which case the ^U prefix will |
| 100 | ;; do the opposite of what was described above. | 100 | ;; do the opposite of what was described above. |
| 101 | ;; | 101 | ;; |
| 102 | ;; THERE ARE FIVE AVAILABLE HOOKS, called in this order if non-nil: | 102 | ;; THERE ARE FIVE AVAILABLE HOOKS, called in this order if non-nil: |
| @@ -108,13 +108,7 @@ | |||
| 108 | ;; - ff-post-load-hooks - called just after the other file is 'loaded' | 108 | ;; - ff-post-load-hooks - called just after the other file is 'loaded' |
| 109 | ;; | 109 | ;; |
| 110 | ;; The *load-hooks allow you to place point where you want it in the other | 110 | ;; The *load-hooks allow you to place point where you want it in the other |
| 111 | ;; file. | 111 | ;; file. |
| 112 | |||
| 113 | ;;; Change Log: | ||
| 114 | ;; | ||
| 115 | ;; FEEDBACK: | ||
| 116 | ;; Please send me bug reports, bug fixes, and extensions, so that I can | ||
| 117 | ;; merge them into the master source. | ||
| 118 | 112 | ||
| 119 | ;; CREDITS: | 113 | ;; CREDITS: |
| 120 | ;; Many thanks go to TUSC Computer Systems Pty Ltd for providing an environ- | 114 | ;; Many thanks go to TUSC Computer Systems Pty Ltd for providing an environ- |
| @@ -123,7 +117,7 @@ | |||
| 123 | ;; Many thanks also go to all those who provided valuable feedback throughout | 117 | ;; Many thanks also go to all those who provided valuable feedback throughout |
| 124 | ;; the development of this package: | 118 | ;; the development of this package: |
| 125 | ;; Rolf Ebert in particular, Fritz Knabe, Heddy Boubaker, Sebastian Kremer, | 119 | ;; Rolf Ebert in particular, Fritz Knabe, Heddy Boubaker, Sebastian Kremer, |
| 126 | ;; Vasco Lopes Paulo, Mark A. Plaksin, Robert Lang, Trevor West, Kevin | 120 | ;; Vasco Lopes Paulo, Mark A. Plaksin, Robert Lang, Trevor West, Kevin |
| 127 | ;; Pereira, Benedict Lofstedt & Justin Vallon. | 121 | ;; Pereira, Benedict Lofstedt & Justin Vallon. |
| 128 | 122 | ||
| 129 | ;;; Code: | 123 | ;;; Code: |
| @@ -133,6 +127,7 @@ | |||
| 133 | (defgroup ff nil | 127 | (defgroup ff nil |
| 134 | "Find a file corresponding to this one given a pattern." | 128 | "Find a file corresponding to this one given a pattern." |
| 135 | :prefix "ff-" | 129 | :prefix "ff-" |
| 130 | :link '(emacs-commentary-link "find-file") | ||
| 136 | :group 'find-file) | 131 | :group 'find-file) |
| 137 | 132 | ||
| 138 | (defcustom ff-pre-find-hooks nil | 133 | (defcustom ff-pre-find-hooks nil |
| @@ -187,7 +182,7 @@ To override this, give an argument to `ff-find-other-file'." | |||
| 187 | :type 'boolean | 182 | :type 'boolean |
| 188 | :group 'ff) | 183 | :group 'ff) |
| 189 | 184 | ||
| 190 | (defvar ff-special-constructs | 185 | (defvar ff-special-constructs |
| 191 | '( | 186 | '( |
| 192 | ;; C/C++ include, for NeXTSTEP too | 187 | ;; C/C++ include, for NeXTSTEP too |
| 193 | ("^\#\\s *\\(include\\|import\\)\\s +[<\"]\\(.*\\)[>\"]" . | 188 | ("^\#\\s *\\(include\\|import\\)\\s +[<\"]\\(.*\\)[>\"]" . |
| @@ -202,9 +197,10 @@ To override this, give an argument to `ff-find-other-file'." | |||
| 202 | (setq fname (concat (ada-make-filename-from-adaname fname) | 197 | (setq fname (concat (ada-make-filename-from-adaname fname) |
| 203 | ada-spec-suffix)))) | 198 | ada-spec-suffix)))) |
| 204 | ) | 199 | ) |
| 205 | "*A list of regular expressions specifying how to recognise special | 200 | "*A list of regular expressions for `ff-find-file'. |
| 206 | constructs such as include files etc, and an associated method for | 201 | Specifies how to recognise special constructs such as include files |
| 207 | extracting the filename from that construct.") | 202 | etc. and an associated method for extracting the filename from that |
| 203 | construct.") | ||
| 208 | 204 | ||
| 209 | (defcustom ff-other-file-alist 'cc-other-file-alist | 205 | (defcustom ff-other-file-alist 'cc-other-file-alist |
| 210 | "*Alist of extensions to find given the current file's extension. | 206 | "*Alist of extensions to find given the current file's extension. |
| @@ -228,7 +224,7 @@ This list is searched through with each extension specified in | |||
| 228 | longer the list, the longer it'll take to realise that a file | 224 | longer the list, the longer it'll take to realise that a file |
| 229 | may not exist. | 225 | may not exist. |
| 230 | 226 | ||
| 231 | A typical format is | 227 | A typical format is |
| 232 | 228 | ||
| 233 | '(\".\" \"/usr/include\" \"$PROJECT/*/include\") | 229 | '(\".\" \"/usr/include\" \"$PROJECT/*/include\") |
| 234 | 230 | ||
| @@ -306,7 +302,7 @@ is created with the first matching extension (`.cc' yields `.hh')." | |||
| 306 | ;;;###autoload | 302 | ;;;###autoload |
| 307 | (defun ff-get-other-file (&optional in-other-window) | 303 | (defun ff-get-other-file (&optional in-other-window) |
| 308 | "Find the header or source file corresponding to this file. | 304 | "Find the header or source file corresponding to this file. |
| 309 | See also the documentation for `ff-find-other-file;. | 305 | See also the documentation for `ff-find-other-file'. |
| 310 | 306 | ||
| 311 | If optional IN-OTHER-WINDOW is non-nil, find the file in another window." | 307 | If optional IN-OTHER-WINDOW is non-nil, find the file in another window." |
| 312 | (interactive "P") | 308 | (interactive "P") |
| @@ -325,48 +321,48 @@ If optional IGNORE-INCLUDE is non-nil, ignore being on `#include' lines. | |||
| 325 | 321 | ||
| 326 | Variables of interest include: | 322 | Variables of interest include: |
| 327 | 323 | ||
| 328 | - ff-case-fold-search | 324 | - `ff-case-fold-search' |
| 329 | Non-nil means ignore cases in matches (see case-fold-search). | 325 | Non-nil means ignore cases in matches (see `case-fold-search'). |
| 330 | If you have extensions in different cases, you will want this to be nil. | 326 | If you have extensions in different cases, you will want this to be nil. |
| 331 | 327 | ||
| 332 | - ff-always-in-other-window | 328 | - `ff-always-in-other-window' |
| 333 | If non-nil, always open the other file in another window, unless an | 329 | If non-nil, always open the other file in another window, unless an |
| 334 | argument is given to ff-find-other-file. | 330 | argument is given to `ff-find-other-file'. |
| 335 | 331 | ||
| 336 | - ff-ignore-include | 332 | - `ff-ignore-include' |
| 337 | If non-nil, ignores #include lines. | 333 | If non-nil, ignores #include lines. |
| 338 | 334 | ||
| 339 | - ff-always-try-to-create | 335 | - `ff-always-try-to-create' |
| 340 | If non-nil, always attempt to create the other file if it was not found. | 336 | If non-nil, always attempt to create the other file if it was not found. |
| 341 | 337 | ||
| 342 | - ff-quiet-mode | 338 | - `ff-quiet-mode' |
| 343 | If non-nil, traces which directories are being searched. | 339 | If non-nil, traces which directories are being searched. |
| 344 | 340 | ||
| 345 | - ff-special-constructs | 341 | - `ff-special-constructs' |
| 346 | A list of regular expressions specifying how to recognise special | 342 | A list of regular expressions specifying how to recognise special |
| 347 | constructs such as include files etc, and an associated method for | 343 | constructs such as include files etc, and an associated method for |
| 348 | extracting the filename from that construct. | 344 | extracting the filename from that construct. |
| 349 | 345 | ||
| 350 | - ff-other-file-alist | 346 | - `ff-other-file-alist' |
| 351 | Alist of extensions to find given the current file's extension. | 347 | Alist of extensions to find given the current file's extension. |
| 352 | 348 | ||
| 353 | - ff-search-directories | 349 | - `ff-search-directories' |
| 354 | List of directories searched through with each extension specified in | 350 | List of directories searched through with each extension specified in |
| 355 | ff-other-file-alist that matches this file's extension. | 351 | `ff-other-file-alist' that matches this file's extension. |
| 356 | 352 | ||
| 357 | - ff-pre-find-hooks | 353 | - `ff-pre-find-hooks' |
| 358 | List of functions to be called before the search for the file starts. | 354 | List of functions to be called before the search for the file starts. |
| 359 | 355 | ||
| 360 | - ff-pre-load-hooks | 356 | - `ff-pre-load-hooks' |
| 361 | List of functions to be called before the other file is loaded. | 357 | List of functions to be called before the other file is loaded. |
| 362 | 358 | ||
| 363 | - ff-post-load-hooks | 359 | - `ff-post-load-hooks' |
| 364 | List of functions to be called after the other file is loaded. | 360 | List of functions to be called after the other file is loaded. |
| 365 | 361 | ||
| 366 | - ff-not-found-hooks | 362 | - `ff-not-found-hooks' |
| 367 | List of functions to be called if the other file could not be found. | 363 | List of functions to be called if the other file could not be found. |
| 368 | 364 | ||
| 369 | - ff-file-created-hooks | 365 | - `ff-file-created-hooks' |
| 370 | List of functions to be called if the other file has been created." | 366 | List of functions to be called if the other file has been created." |
| 371 | (interactive "P") | 367 | (interactive "P") |
| 372 | (let ((ignore ff-ignore-include)) | 368 | (let ((ignore ff-ignore-include)) |
| @@ -393,8 +389,8 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window." | |||
| 393 | alist ;; working copy of the list of file extensions | 389 | alist ;; working copy of the list of file extensions |
| 394 | pathname ;; the pathname of the file or the #include line | 390 | pathname ;; the pathname of the file or the #include line |
| 395 | default-name ;; file we should create if none found | 391 | default-name ;; file we should create if none found |
| 396 | format ;; what we have to match | 392 | format ;; what we have to match |
| 397 | found ;; name of the file or buffer found - nil if none | 393 | found ;; name of the file or buffer found - nil if none |
| 398 | dirs ;; local value of ff-search-directories | 394 | dirs ;; local value of ff-search-directories |
| 399 | no-match) ;; whether we know about this kind of file | 395 | no-match) ;; whether we know about this kind of file |
| 400 | 396 | ||
| @@ -447,7 +443,7 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window." | |||
| 447 | action (car (cdr match)) | 443 | action (car (cdr match)) |
| 448 | found nil) | 444 | found nil) |
| 449 | 445 | ||
| 450 | ;; if we have a function to generate new names, | 446 | ;; if we have a function to generate new names, |
| 451 | ;; invoke it with the name of the current file | 447 | ;; invoke it with the name of the current file |
| 452 | (if (and (atom action) (fboundp action)) | 448 | (if (and (atom action) (fboundp action)) |
| 453 | (progn | 449 | (progn |
| @@ -457,7 +453,7 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window." | |||
| 457 | default-name (car suffixes))) | 453 | default-name (car suffixes))) |
| 458 | 454 | ||
| 459 | ;; otherwise build our filename stub | 455 | ;; otherwise build our filename stub |
| 460 | (cond | 456 | (cond |
| 461 | 457 | ||
| 462 | ;; get around the problem that 0 and nil both mean false! | 458 | ;; get around the problem that 0 and nil both mean false! |
| 463 | ((= pos 0) | 459 | ((= pos 0) |
| @@ -476,17 +472,17 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window." | |||
| 476 | (concat stub (car (car (cdr match)))))) | 472 | (concat stub (car (car (cdr match)))))) |
| 477 | 473 | ||
| 478 | ;; do the real work - find the file | 474 | ;; do the real work - find the file |
| 479 | (setq found | 475 | (setq found |
| 480 | (ff-get-file dirs | 476 | (ff-get-file dirs |
| 481 | stub | 477 | stub |
| 482 | suffixes | 478 | suffixes |
| 483 | in-other-window))))) | 479 | in-other-window))))) |
| 484 | 480 | ||
| 485 | (cond | 481 | (cond |
| 486 | (no-match ;; could not even determine the other file | 482 | (no-match ;; could not even determine the other file |
| 487 | (message "")) | 483 | (message "")) |
| 488 | 484 | ||
| 489 | (t | 485 | (t |
| 490 | (cond | 486 | (cond |
| 491 | 487 | ||
| 492 | ((not found) ;; could not find the other file | 488 | ((not found) ;; could not find the other file |
| @@ -494,7 +490,7 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window." | |||
| 494 | (if ff-not-found-hooks ;; run the hooks | 490 | (if ff-not-found-hooks ;; run the hooks |
| 495 | (run-hooks 'ff-not-found-hooks)) | 491 | (run-hooks 'ff-not-found-hooks)) |
| 496 | 492 | ||
| 497 | (cond | 493 | (cond |
| 498 | (ff-always-try-to-create ;; try to create the file | 494 | (ff-always-try-to-create ;; try to create the file |
| 499 | (let (name pathname) | 495 | (let (name pathname) |
| 500 | 496 | ||
| @@ -519,17 +515,14 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window." | |||
| 519 | 515 | ||
| 520 | found)) ;; return buffer-name or filename | 516 | found)) ;; return buffer-name or filename |
| 521 | 517 | ||
| 522 | (defun ff-get-file (search-dirs fname-stub &optional suffix-list other-window) | 518 | (defun ff-get-file (search-dirs filename &optional suffix-list other-window) |
| 523 | "Find a file in the SEARCH-DIRS with the given FILENAME (or filename stub). | 519 | "Find a file in the SEARCH-DIRS with the given FILENAME (or filename stub). |
| 524 | If (optional) SUFFIXES is nil, search for fname, otherwise search for fname | 520 | If (optional) SUFFIX-LIST is nil, search for fname, otherwise search |
| 525 | with each of the given suffixes. Gets the file or the buffer corresponding | 521 | for fname with each of the given suffixes. Get the file or the buffer |
| 526 | to the name of the first file found, or nil. | 522 | corresponding to the name of the first file found, or nil." |
| 527 | 523 | (let ((filename (ff-get-file-name search-dirs filename suffix-list))) | |
| 528 | Arguments: (search-dirs fname-stub &optional suffix-list in-other-window) | ||
| 529 | " | ||
| 530 | (let ((filename (ff-get-file-name search-dirs fname-stub suffix-list))) | ||
| 531 | 524 | ||
| 532 | (cond | 525 | (cond |
| 533 | ((not filename) | 526 | ((not filename) |
| 534 | nil) | 527 | nil) |
| 535 | 528 | ||
| @@ -545,12 +538,10 @@ Arguments: (search-dirs fname-stub &optional suffix-list in-other-window) | |||
| 545 | nil)))) | 538 | nil)))) |
| 546 | 539 | ||
| 547 | (defun ff-get-file-name (search-dirs fname-stub &optional suffix-list) | 540 | (defun ff-get-file-name (search-dirs fname-stub &optional suffix-list) |
| 548 | "Find a file in the SEARCH-DIRS with the given FILENAME (or filename stub). | 541 | "Find a file in SEARCH-DIRS with the given name (or stub) FNAME-STUB. |
| 549 | If (optional) SUFFIXES is nil, search for fname, otherwise search for fname | 542 | If (optional) SUFFIX-LIST is nil, search for FNAME-STUB, otherwise |
| 550 | with each of the given suffixes. Returns the name of the first file found. | 543 | search for FNAME-STUB with each of the given suffixes. Return the |
| 551 | 544 | name of the first file found." | |
| 552 | Arguments: (search-dirs fname-stub &optional suffix-list) | ||
| 553 | " | ||
| 554 | (let* (dirs ;; working copy of dirs to search | 545 | (let* (dirs ;; working copy of dirs to search |
| 555 | dir ;; the current dir considered | 546 | dir ;; the current dir considered |
| 556 | file ;; filename being looked for | 547 | file ;; filename being looked for |
| @@ -603,7 +594,7 @@ Arguments: (search-dirs fname-stub &optional suffix-list) | |||
| 603 | 594 | ||
| 604 | ;; if dir does not contain '/*', look for the file | 595 | ;; if dir does not contain '/*', look for the file |
| 605 | (if (and dir (not (string-match "\\([^*]*\\)/\\\*\\(/.*\\)*" dir))) | 596 | (if (and dir (not (string-match "\\([^*]*\\)/\\\*\\(/.*\\)*" dir))) |
| 606 | (progn | 597 | (progn |
| 607 | 598 | ||
| 608 | ;; suffixes is nil => fname-stub is the file we are looking for | 599 | ;; suffixes is nil => fname-stub is the file we are looking for |
| 609 | ;; otherwise fname-stub is a stub, and we append a suffix | 600 | ;; otherwise fname-stub is a stub, and we append a suffix |
| @@ -683,7 +674,7 @@ The value used comes from `ff-case-fold-search'." | |||
| 683 | (setq search-list (reverse list)))) | 674 | (setq search-list (reverse list)))) |
| 684 | 675 | ||
| 685 | (defun ff-treat-as-special () | 676 | (defun ff-treat-as-special () |
| 686 | "Returns the file to look for if the construct was special, else nil. | 677 | "Return the file to look for if the construct was special, else nil. |
| 687 | The construct is defined in the variable `ff-special-constructs'." | 678 | The construct is defined in the variable `ff-special-constructs'." |
| 688 | (let* (fname | 679 | (let* (fname |
| 689 | (list ff-special-constructs) | 680 | (list ff-special-constructs) |
| @@ -700,7 +691,7 @@ The construct is defined in the variable `ff-special-constructs'." | |||
| 700 | fname)) | 691 | fname)) |
| 701 | 692 | ||
| 702 | (defun ff-basename (string) | 693 | (defun ff-basename (string) |
| 703 | "Return the basename of PATHNAME." | 694 | "Return the basename of pathname STRING." |
| 704 | (setq string (concat "/" string)) | 695 | (setq string (concat "/" string)) |
| 705 | (string-match ".*/\\([^/]+\\)$" string) | 696 | (string-match ".*/\\([^/]+\\)$" string) |
| 706 | (setq string (substring string (match-beginning 1) (match-end 1)))) | 697 | (setq string (substring string (match-beginning 1) (match-end 1)))) |
| @@ -736,7 +727,7 @@ and on the global variable `ff-always-in-other-window'. | |||
| 736 | F1 and F2 are typically `find-file' / `find-file-other-window' | 727 | F1 and F2 are typically `find-file' / `find-file-other-window' |
| 737 | or `switch-to-buffer' / `switch-to-buffer-other-window' function pairs. | 728 | or `switch-to-buffer' / `switch-to-buffer-other-window' function pairs. |
| 738 | 729 | ||
| 739 | If optional NEW-FILE is t, then a special hook (`ff-file-created-hooks') is | 730 | If optional NEW-FILE is t, then a special hook (`ff-file-created-hooks') is |
| 740 | called before `ff-post-load-hooks'." | 731 | called before `ff-post-load-hooks'." |
| 741 | (if ff-pre-load-hooks | 732 | (if ff-pre-load-hooks |
| 742 | (run-hooks 'ff-pre-load-hooks)) | 733 | (run-hooks 'ff-pre-load-hooks)) |
| @@ -753,44 +744,38 @@ called before `ff-post-load-hooks'." | |||
| 753 | 744 | ||
| 754 | (defun ff-find-file (file &optional in-other-window new-file) | 745 | (defun ff-find-file (file &optional in-other-window new-file) |
| 755 | "Like `find-file', but may show the file in another window." | 746 | "Like `find-file', but may show the file in another window." |
| 756 | (ff-switch-file 'find-file | 747 | (ff-switch-file 'find-file |
| 757 | 'find-file-other-window | 748 | 'find-file-other-window |
| 758 | file in-other-window new-file)) | 749 | file in-other-window new-file)) |
| 759 | 750 | ||
| 760 | (defun ff-switch-to-buffer (buffer-or-name &optional in-other-window) | 751 | (defun ff-switch-to-buffer (buffer-or-name &optional in-other-window) |
| 761 | "Like `switch-to-buffer', but may show the buffer in another window." | 752 | "Like `switch-to-buffer', but may show the buffer in another window." |
| 762 | 753 | ||
| 763 | (ff-switch-file 'switch-to-buffer | 754 | (ff-switch-file 'switch-to-buffer |
| 764 | 'switch-to-buffer-other-window | 755 | 'switch-to-buffer-other-window |
| 765 | buffer-or-name in-other-window nil)) | 756 | buffer-or-name in-other-window nil)) |
| 766 | 757 | ||
| 767 | (defun ff-goto-click (event) | ||
| 768 | (set-buffer (window-buffer (posn-window (event-end event)))) | ||
| 769 | (goto-char (posn-point (event-end event)))) | ||
| 770 | |||
| 771 | ;;;###autoload | 758 | ;;;###autoload |
| 772 | (defun ff-mouse-find-other-file (event) | 759 | (defun ff-mouse-find-other-file (event) |
| 773 | "Visit the file you click on." | 760 | "Visit the file you click on." |
| 774 | (interactive "e") | 761 | (interactive "e") |
| 775 | (save-excursion | 762 | (save-excursion |
| 776 | (ff-goto-click event) | 763 | (mouse-set-point event) |
| 777 | (ff-find-other-file nil))) | 764 | (ff-find-other-file nil))) |
| 778 | 765 | ||
| 779 | ;;;###autoload | 766 | ;;;###autoload |
| 780 | (defun ff-mouse-find-other-file-other-window (event) | 767 | (defun ff-mouse-find-other-file-other-window (event) |
| 781 | "Visit the file you click on." | 768 | "Visit the file you click on in another window." |
| 782 | (interactive "e") | 769 | (interactive "e") |
| 783 | (save-excursion | 770 | (save-excursion |
| 784 | (ff-goto-click event) | 771 | (mouse-set-point event) |
| 785 | (ff-find-other-file t))) | 772 | (ff-find-other-file t))) |
| 786 | 773 | ||
| 787 | (provide 'find-file) | ||
| 788 | |||
| 789 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 774 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 790 | ;; This section offers an example of user defined function to select files | 775 | ;; This section offers an example of user defined function to select files |
| 791 | 776 | ||
| 792 | (defun ff-upcase-p (string &optional start end) | 777 | (defun ff-upcase-p (string &optional start end) |
| 793 | "Return t if this string is all uppercase. | 778 | "Return t if STRING is all uppercase. |
| 794 | Given START and/or END, checks between these characters." | 779 | Given START and/or END, checks between these characters." |
| 795 | (let (match str) | 780 | (let (match str) |
| 796 | (if (not start) | 781 | (if (not start) |
| @@ -800,7 +785,7 @@ Given START and/or END, checks between these characters." | |||
| 800 | (if (= start end) | 785 | (if (= start end) |
| 801 | (setq end (1+ end))) | 786 | (setq end (1+ end))) |
| 802 | (setq str (substring string start end)) | 787 | (setq str (substring string start end)) |
| 803 | (if (and | 788 | (if (and |
| 804 | (ff-string-match "[A-Z]+" str) | 789 | (ff-string-match "[A-Z]+" str) |
| 805 | (setq match (match-data)) | 790 | (setq match (match-data)) |
| 806 | (= (car match) 0) | 791 | (= (car match) 0) |
| @@ -813,18 +798,18 @@ Given START and/or END, checks between these characters." | |||
| 813 | Build up a new file list based possibly on part of the directory name | 798 | Build up a new file list based possibly on part of the directory name |
| 814 | and the name of the file passed in." | 799 | and the name of the file passed in." |
| 815 | (ff-string-match "\\(.*\\)/\\([^/]+\\)/\\([^.]+\\).\\([^/]+\\)$" arg) | 800 | (ff-string-match "\\(.*\\)/\\([^/]+\\)/\\([^.]+\\).\\([^/]+\\)$" arg) |
| 816 | (let ((path (if (match-beginning 1) | 801 | (let ((path (if (match-beginning 1) |
| 817 | (substring arg (match-beginning 1) (match-end 1)) nil)) | 802 | (substring arg (match-beginning 1) (match-end 1)) nil)) |
| 818 | (dire (if (match-beginning 2) | 803 | (dire (if (match-beginning 2) |
| 819 | (substring arg (match-beginning 2) (match-end 2)) nil)) | 804 | (substring arg (match-beginning 2) (match-end 2)) nil)) |
| 820 | (file (if (match-beginning 3) | 805 | (file (if (match-beginning 3) |
| 821 | (substring arg (match-beginning 3) (match-end 3)) nil)) | 806 | (substring arg (match-beginning 3) (match-end 3)) nil)) |
| 822 | (extn (if (match-beginning 4) | 807 | (extn (if (match-beginning 4) |
| 823 | (substring arg (match-beginning 4) (match-end 4)) nil)) | 808 | (substring arg (match-beginning 4) (match-end 4)) nil)) |
| 824 | return-list) | 809 | return-list) |
| 825 | (cond | 810 | (cond |
| 826 | ;; fooZapJunk.cc => ZapJunk.{hh,h} or fooZapJunk.{hh,h} | 811 | ;; fooZapJunk.cc => ZapJunk.{hh,h} or fooZapJunk.{hh,h} |
| 827 | ((and (string= extn "cc") | 812 | ((and (string= extn "cc") |
| 828 | (ff-string-match "^\\([a-z]+\\)\\([A-Z].+\\)$" file)) | 813 | (ff-string-match "^\\([a-z]+\\)\\([A-Z].+\\)$" file)) |
| 829 | (let ((stub (substring file (match-beginning 2) (match-end 2)))) | 814 | (let ((stub (substring file (match-beginning 2) (match-end 2)))) |
| 830 | (setq dire (upcase (substring file (match-beginning 1) (match-end 1)))) | 815 | (setq dire (upcase (substring file (match-beginning 1) (match-end 1)))) |
| @@ -836,7 +821,7 @@ and the name of the file passed in." | |||
| 836 | ;; FOO/ZapJunk.hh => fooZapJunk.{cc,C} or ZapJunk.{cc,C} | 821 | ;; FOO/ZapJunk.hh => fooZapJunk.{cc,C} or ZapJunk.{cc,C} |
| 837 | ((and (string= extn "hh") (ff-upcase-p dire) file) | 822 | ((and (string= extn "hh") (ff-upcase-p dire) file) |
| 838 | (let ((stub (concat (downcase dire) file))) | 823 | (let ((stub (concat (downcase dire) file))) |
| 839 | (setq return-list (list (concat stub ".cc") | 824 | (setq return-list (list (concat stub ".cc") |
| 840 | (concat stub ".C") | 825 | (concat stub ".C") |
| 841 | (concat file ".cc") | 826 | (concat file ".cc") |
| 842 | (concat file ".C"))) | 827 | (concat file ".C"))) |
| @@ -853,7 +838,7 @@ and the name of the file passed in." | |||
| 853 | (setq return-list (list (concat stub ".cc") | 838 | (setq return-list (list (concat stub ".cc") |
| 854 | (concat stub ".C"))) | 839 | (concat stub ".C"))) |
| 855 | )) | 840 | )) |
| 856 | (t | 841 | (t |
| 857 | nil)) | 842 | nil)) |
| 858 | 843 | ||
| 859 | return-list)) | 844 | return-list)) |
| @@ -894,5 +879,6 @@ That name was previously determined by `ff-which-function-are-we-in'." | |||
| 894 | (goto-char (point-min)) | 879 | (goto-char (point-min)) |
| 895 | (search-forward ff-function-name nil t)))) | 880 | (search-forward ff-function-name nil t)))) |
| 896 | 881 | ||
| 897 | ;; find-file.el ends here | 882 | (provide 'find-file) |
| 898 | 883 | ||
| 884 | ;;; find-file.el ends here | ||