* naming convention based file toggling facility
@ 2003-09-25 7:07 Robert Anderson
2003-09-25 7:20 ` Masatake YAMATO
2003-09-25 10:27 ` Kim F. Storm
0 siblings, 2 replies; 7+ messages in thread
From: Robert Anderson @ 2003-09-25 7:07 UTC (permalink / raw)
I've had a hackish little elisp function for years that always struck me
as a slightly surprising omission from emacs: the ability to toggle
between files based on a naming convention like: <source>.c and
<source>.h.
This of course, generalizes to more contexts. I use it for toggling
between header, implementation, and unittest files, for example, based
on the convention that the corresonding unittest file is
<source>-test.c. I'm sure it's useful elsewhere, given a reasonable
method for defining the relationship between the names of the related
files.
This kind of "toggle header" or "toggle source" function is standard IDE
fare. I got used to it from a previous life when I was using Metrowerks
Codewarrior. It's _very_ handy, IMO.
Is there some reason that such a thing is not included in emacs? Maybe
it's there and I've missed it? Would the maintainers be interested in
such a facility if I were to write it?
Bob
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: naming convention based file toggling facility
2003-09-25 7:07 naming convention based file toggling facility Robert Anderson
@ 2003-09-25 7:20 ` Masatake YAMATO
2003-09-25 7:24 ` Robert Anderson
2003-09-25 23:21 ` Richard Stallman
2003-09-25 10:27 ` Kim F. Storm
1 sibling, 2 replies; 7+ messages in thread
From: Masatake YAMATO @ 2003-09-25 7:20 UTC (permalink / raw)
Cc: emacs-devel
> I've had a hackish little elisp function for years that always struck me
> as a slightly surprising omission from emacs: the ability to toggle
> between files based on a naming convention like: <source>.c and
> <source>.h.
M-x ff-find-other-file may be useful.
I have another implementation.
Masatake YAMATO
;; c-alt.el --- Find header file or implementation file
;; Copyright (C) 2000 Masatake YAMATO
;; Author Masatake YAMATO <jet@gyve.org>
;; Created: Tue Jun 4 17:00:22 1996
;; Time-stamp: <00/10/12 20:30:48 masata-y>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;; Commentary:
;;
;; Put .emacs
;;
;; (add-hook 'c-mode-hook (function (lambda ()
;; (define-key c-mode-map "\C-c\C-v" 'c-find-alternative-file))))
;; (autoload 'c-find-alternative-file "c-alt" "Find .c or .h file" t)
;; Histroy
;; * Thu Oct 12 20:06:36 2000
;; Added c++ supports
(defun c-find-alternative-file (arg)
"TODO"
(interactive "P")
(let* ((fname (buffer-file-name))
(basename (file-name-sans-extension fname))
(afname nil)
(baselen (length basename))
(ext (substring fname (1+ baselen))))
(cond
((or (string= ext "c") (string= ext "m") (string= ext "cpp"))
(setq afname (concat basename ".h"))
(if (file-exists-p afname)
(find-file afname)
(if arg
(find-file afname)
(if (y-or-n-p (format "Cannot find! Create %s?: " afname))
(find-file afname)
))
))
((string= ext "h")
(if (or
(progn (setq afname (concat basename ".m")) (file-exists-p afname))
(progn (setq afname (concat basename ".c")) (file-exists-p afname))
(progn (setq afname (concat basename ".cpp")) (file-exists-p afname)))
(find-file afname)
(let ((newext (call-interactively 'c-get-alternative-file-name)))
(setq afname (concat basename (cond
((eq newext ?+)
".cpp")
((eq newext ?c)
".c")
((eq newext ?m)
".m")
((eq newext ?n)
"")
((eq newext ?y)
".c")
(t
"")
)))
(if (not (eq newext ?n))
(if (not (eq baselen (length afname)))
(find-file afname)
(error "Wrong extension: %c" newext))))))
(t
(error "No alternative file for: %c" fname)))))
(defun c-get-alternative-file-name (ext)
(interactive "cCannot find! Create?(type n(No) c(C), m(ObjC) or +(C++)): ")
ext)
(provide 'c-alt)
;; c-alt.el ends here.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: naming convention based file toggling facility
2003-09-25 7:20 ` Masatake YAMATO
@ 2003-09-25 7:24 ` Robert Anderson
2003-09-25 23:21 ` Richard Stallman
1 sibling, 0 replies; 7+ messages in thread
From: Robert Anderson @ 2003-09-25 7:24 UTC (permalink / raw)
On Thu, 2003-09-25 at 00:20, Masatake YAMATO wrote:
> > I've had a hackish little elisp function for years that always struck me
> > as a slightly surprising omission from emacs: the ability to toggle
> > between files based on a naming convention like: <source>.c and
> > <source>.h.
>
> M-x ff-find-other-file may be useful.
>
> I have another implementation.
Well look at that. I'll take a look at both, but it looks pretty close
to what I had in mind. Thanks!
Bob
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: naming convention based file toggling facility
2003-09-25 7:20 ` Masatake YAMATO
2003-09-25 7:24 ` Robert Anderson
@ 2003-09-25 23:21 ` Richard Stallman
2003-09-26 6:03 ` Masatake YAMATO
1 sibling, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2003-09-25 23:21 UTC (permalink / raw)
Cc: rwa, emacs-devel
> I've had a hackish little elisp function for years that always struck me
> as a slightly surprising omission from emacs: the ability to toggle
> between files based on a naming convention like: <source>.c and
> <source>.h.
M-x ff-find-other-file may be useful.
If this does the job, maybe CC mode should provide bindings and menu
bar entrie for it--or for some other clean interface to it.
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: naming convention based file toggling facility
2003-09-25 23:21 ` Richard Stallman
@ 2003-09-26 6:03 ` Masatake YAMATO
2003-09-27 2:31 ` Richard Stallman
0 siblings, 1 reply; 7+ messages in thread
From: Masatake YAMATO @ 2003-09-26 6:03 UTC (permalink / raw)
Cc: bug-cc-mode, rwa, emacs-devel
> > I've had a hackish little elisp function for years that always struck me
> > as a slightly surprising omission from emacs: the ability to toggle
> > between files based on a naming convention like: <source>.c and
> > <source>.h.
>
> M-x ff-find-other-file may be useful.
>
> If this does the job, maybe CC mode should provide bindings and menu
> bar entrie for it--or for some other clean interface to it.
ff-find-other-file is useful particularly in c-mode and c++-mode.
However it may be useful in other modes.
e.g. moving between *gud* buffer and .gdbinit.
Next patch is prosaic but it works.
Masatake YAMATO
Index: lisp/bindings.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.123
diff -u -r1.123 bindings.el
--- lisp/bindings.el 8 Sep 2003 08:02:45 -0000 1.123
+++ lisp/bindings.el 26 Sep 2003 05:56:23 -0000
@@ -371,6 +371,13 @@
(interactive)
(switch-to-buffer (other-buffer)))
+(defun mode-line-ff-other-file (event) "\
+Find the header or source file corresponding to the current buffer."
+ (interactive "e")
+ (save-selected-window
+ (select-window (posn-window (event-start event)))
+ (ff-find-the-other-file)))
+
(defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\
Menu of mode operations in the mode line.")
@@ -449,6 +456,7 @@
(define-key map [mode-line mouse-3] 'mode-line-bury-buffer)
(define-key map [header-line down-mouse-3] 'ignore)
(define-key map [header-line mouse-3] 'mode-line-bury-buffer)
+ (define-key map [mode-line mouse-2] 'mode-line-ff-other-file)
(setq mode-line-buffer-identification-keymap map))
(defun propertized-buffer-identification (fmt)
@@ -458,7 +466,7 @@
(list (propertize fmt
'face '(:weight bold)
'help-echo
- (purecopy "mouse-1: previous buffer, mouse-3: next buffer")
+ (purecopy "mouse-1: previous buffer, mouse-2: find related file, mouse-3: next buffer")
'local-map mode-line-buffer-identification-keymap)))
(setq-default mode-line-buffer-identification
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: naming convention based file toggling facility
2003-09-26 6:03 ` Masatake YAMATO
@ 2003-09-27 2:31 ` Richard Stallman
0 siblings, 0 replies; 7+ messages in thread
From: Richard Stallman @ 2003-09-27 2:31 UTC (permalink / raw)
Cc: bug-cc-mode, rwa, emacs-devel
I think the menu bar is a more natural place to put this. Can you set
it up so that when in a source file, the menu bar item name says
"Header File", and when in a header file, the menu bar item name says
"Source File"?
Ideally, the menu bar item should be enabled only when there
is a corresponding file to go to.
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: naming convention based file toggling facility
2003-09-25 7:07 naming convention based file toggling facility Robert Anderson
2003-09-25 7:20 ` Masatake YAMATO
@ 2003-09-25 10:27 ` Kim F. Storm
1 sibling, 0 replies; 7+ messages in thread
From: Kim F. Storm @ 2003-09-25 10:27 UTC (permalink / raw)
Cc: emacs
Robert Anderson <rwa@alumni.princeton.edu> writes:
> I've had a hackish little elisp function for years that always struck me
> as a slightly surprising omission from emacs: the ability to toggle
> between files based on a naming convention like: <source>.c and
> <source>.h.
>
If you use ido-mode, and your current buffer is xyz.c, then you can
enter C-x C-f C-w to see only the xyz.<something> files.
I realize now that a similar function would be handly when switching
buffers.
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-09-27 2:31 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-25 7:07 naming convention based file toggling facility Robert Anderson
2003-09-25 7:20 ` Masatake YAMATO
2003-09-25 7:24 ` Robert Anderson
2003-09-25 23:21 ` Richard Stallman
2003-09-26 6:03 ` Masatake YAMATO
2003-09-27 2:31 ` Richard Stallman
2003-09-25 10:27 ` Kim F. Storm
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).