514 |
|
|
515 |
found)) ;; return buffer-name or filename |
found)) ;; return buffer-name or filename |
516 |
|
|
517 |
|
(defun ff-other-file-name () |
518 |
|
"Return name of the header or source file corresponding to the current file. |
519 |
|
Being on a `#include' line pulls in that file, but see the help on |
520 |
|
the `ff-ignore-include' variable." |
521 |
|
|
522 |
|
(let (match ;; matching regexp for this file |
523 |
|
suffixes ;; set of replacing regexps for the matching regexp |
524 |
|
action ;; function to generate the names of the other files |
525 |
|
fname ;; basename of this file |
526 |
|
pos ;; where we start matching filenames |
527 |
|
stub ;; name of the file without extension |
528 |
|
alist ;; working copy of the list of file extensions |
529 |
|
pathname ;; the pathname of the file or the #include line |
530 |
|
default-name ;; file we should create if none found |
531 |
|
format ;; what we have to match |
532 |
|
found ;; name of the file or buffer found - nil if none |
533 |
|
dirs ;; local value of ff-search-directories |
534 |
|
no-match) ;; whether we know about this kind of file |
535 |
|
|
536 |
|
(message "Working...") |
537 |
|
|
538 |
|
(setq dirs |
539 |
|
(if (symbolp ff-search-directories) |
540 |
|
(ff-list-replace-env-vars (symbol-value ff-search-directories)) |
541 |
|
(ff-list-replace-env-vars ff-search-directories))) |
542 |
|
|
543 |
|
(save-excursion |
544 |
|
(beginning-of-line 1) |
545 |
|
(setq fname (ff-treat-as-special))) |
546 |
|
|
547 |
|
(cond |
548 |
|
((and (not ff-ignore-include) fname) |
549 |
|
(setq default-name fname) |
550 |
|
(setq found (ff-get-file-name dirs fname nil))) |
551 |
|
|
552 |
|
;; let's just get the corresponding file |
553 |
|
(t |
554 |
|
(setq alist (if (symbolp ff-other-file-alist) |
555 |
|
(symbol-value ff-other-file-alist) |
556 |
|
ff-other-file-alist) |
557 |
|
pathname (if (buffer-file-name) |
558 |
|
(buffer-file-name) |
559 |
|
"/none.none")) |
560 |
|
|
561 |
|
(setq fname (file-name-nondirectory pathname) |
562 |
|
no-match nil |
563 |
|
match (car alist)) |
564 |
|
|
565 |
|
;; find the table entry corresponding to this file |
566 |
|
(setq pos (ff-string-match (car match) fname)) |
567 |
|
(while (and match (if (and pos (>= pos 0)) nil (not pos))) |
568 |
|
(setq alist (cdr alist)) |
569 |
|
(setq match (car alist)) |
570 |
|
(setq pos (ff-string-match (car match) fname))) |
571 |
|
|
572 |
|
;; no point going on if we haven't found anything |
573 |
|
(if (not match) |
574 |
|
(setq no-match t) |
575 |
|
|
576 |
|
;; otherwise, suffixes contains what we need |
577 |
|
(setq suffixes (car (cdr match)) |
578 |
|
action (car (cdr match)) |
579 |
|
found nil) |
580 |
|
|
581 |
|
;; if we have a function to generate new names, |
582 |
|
;; invoke it with the name of the current file |
583 |
|
(if (and (atom action) (fboundp action)) |
584 |
|
(progn |
585 |
|
(setq suffixes (funcall action (buffer-file-name)) |
586 |
|
match (cons (car match) (list suffixes)) |
587 |
|
stub nil |
588 |
|
default-name (car suffixes))) |
589 |
|
|
590 |
|
;; otherwise build our filename stub |
591 |
|
(cond |
592 |
|
|
593 |
|
;; get around the problem that 0 and nil both mean false! |
594 |
|
((= pos 0) |
595 |
|
(setq format "") |
596 |
|
(setq stub "") |
597 |
|
) |
598 |
|
|
599 |
|
(t |
600 |
|
(setq format (concat "\\(.+\\)" (car match))) |
601 |
|
(string-match format fname) |
602 |
|
(setq stub (substring fname (match-beginning 1) (match-end 1))) |
603 |
|
)) |
604 |
|
|
605 |
|
;; if we find nothing, we should try to get a file like this one |
606 |
|
(setq default-name |
607 |
|
(concat stub (car (car (cdr match)))))) |
608 |
|
|
609 |
|
;; do the real work - find the file |
610 |
|
(setq found |
611 |
|
(ff-get-file-name dirs stub suffixes))))) |
612 |
|
found)) ;; return buffer-name or filename |
613 |
|
|
614 |
(defun ff-get-file (search-dirs filename &optional suffix-list other-window) |
(defun ff-get-file (search-dirs filename &optional suffix-list other-window) |
615 |
"Find a file in the SEARCH-DIRS with the given FILENAME (or filename stub). |
"Find a file in the SEARCH-DIRS with the given FILENAME (or filename stub). |
616 |
If (optional) SUFFIX-LIST is nil, search for fname, otherwise search |
If (optional) SUFFIX-LIST is nil, search for fname, otherwise search |