help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help writing file-visiting macro


From: Kevin Rodgers
Subject: Re: Need help writing file-visiting macro
Date: Tue, 26 Jul 2005 09:52:13 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Martin Slouf wrote:
> Is there an easy modification of this piece of code that can help me to find > files in different directories? i guess these are the string manipulation
> functions.

There are also file name manipulation functions, which are generally
preferable to the lower-level string manipulation functions:

file-name-directory
file-name-nondirectory
file-name-extension
file-name-sans-extension
file-name-sans-versions
file-name-as-directory
directory-file-name
expand-file-name

> The situation is like this:
>
> For each business level class (BankAccount.java) (located somewhere under the
> 'src' directory structure) there are at least two jsp pages:
> bank_account_edit_.jsp and bank_account_list_.jsp under the 'web' directory
> structure), ie:
>
> top dir
> +
> |
> +-- src (Java source in packages)
> |    |
> |    +-- somewhere
> |            |
> |            +-- BankAccount.java
> |
> +---web (JSP pages using jakarta-struts)
>      |
>      +-- somewhere
>              |
>              +-- bank_account_edit_.jsp
>         |
>         +-- bak_account_list_.jsp
>
>
> i get those macros (proposed in thi sthread) open the same buffer with
> modified name in the same directory.  My questions are like this:
>
> 1. what string function can be used to make the string BankAccount to
> transform it into bank_account_edit_ and bank_account_list_

Hmmm, CamelCase to lower_case.
http://www.emacswiki.org/cgi-bin/wiki/CamelCase refers to glasses-mode,
which unfortunately doesn't provide a low level utility function to
convert strings.  But you can write your own:

(defun CamelCase-to-lower_case (string)
  (let ((i 0)
        (result "")
        (case-fold-search nil))
    (while (string-match "[[:upper:]][[:lower:]]*" string i)
      (setq result
            (concat result
                    (substring string i (match-beginning 0))
                    (if (> (match-beginning 0) 0) "_")
                    (downcase (match-string 0 string))))
      (setq i (match-end 0)))
    (setq result
          (concat result (substring string i)))))

So (concat (CamelCase-to-lower_case "BankAccount") "_edit_") returns
"bank_account_edit_".

> 2. what functions should be used to open those jsp buffers (java
> buffer respectively)?, when each of this file is / can be in different
> directory?

Just stick with find-file, or perhaps
(switch-to-buffer (find-file-noselect FILE)) or
(pop-to-buffer (find-file-noselect FILE)).

--
Kevin Rodgers





reply via email to

[Prev in Thread] Current Thread [Next in Thread]