all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: Emacs lisp question
Date: Mon, 18 Apr 2016 12:05:16 -0400	[thread overview]
Message-ID: <barmar-81D3F5.12051618042016@88-209-239-213.giganet.hu> (raw)
In-Reply-To: mailman.616.1460989677.7477.help-gnu-emacs@gnu.org

In article <mailman.616.1460989677.7477.help-gnu-emacs@gnu.org>,
 Matthias Pfeifer <mpfeifer77@gmail.com> wrote:

> Hi there,
> 
> My emacs version is 25.0.91.1 and it's running on Windows 7. I have this
> piece of Emacs lisp that does insert a template file in a fresh java-mode
> buffer and start my "pre-processor"
> 
> 
> (add-to-list 'auto-insert-alist '(".*\\.java$" . [ "template.java"
> mp:java-preprocessor] ))
> 
> pre-processor looks like this:
> 
> (defun mp:java-preprocessor()
>   (let ((classname (file-name-sans-extension (buffer-name)))
>     (packagename (mp:predict-package-name-for-current-buffer)))
>     (while (search-forward "CLASSNAME" nil t)
>       (replace-match classname))
>     (goto-char (point-min))
>     (while (search-forward "PACKAGE" nil t)
>       (replace-match packagename) ) ) )
> 
> (defun mp:predict-package-name-for-current-buffer ()
>   "Simply take two parent directories and concat with . inbetween."
>   (let* ((components (remq ""
>                (reverse
>                 (split-string
>                  (file-name-directory (buffer-file-name))
>                  "\\/")))))
>     (concat (nth 0 components) "." (nth 1 components) "." (nth 2
> components))))
> 
> 
> The problem is that the class-name and package-name are actually inserted
> in capital letters while all file-names involved are writtn with lower-case
> letters. So for a file with this path "c:/a/b/c/d/. The predict method
> actually inserts: C.D.

From the documentation of replace-match:

If second arg fixedcase is non-nil, do not alter case of replacement 
text.
Otherwise maybe capitalize the whole text, or maybe just word initials,
based on the replaced text.
If the replaced text has only capital letters
and has at least one multiletter word, convert newtext to all caps.
Otherwise if all words are capitalized in the replaced text,
capitalize each word in newtext.

So use (replace-match packagename t)

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


       reply	other threads:[~2016-04-18 16:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.616.1460989677.7477.help-gnu-emacs@gnu.org>
2016-04-18 16:05 ` Barry Margolin [this message]
2016-04-18 14:27 Emacs lisp question Matthias Pfeifer
2016-04-18 19:50 ` tomas
2016-04-19 10:39   ` Matthias Pfeifer
2016-04-19 11:59 ` Alexis
2016-04-22  9:05   ` Matthias Pfeifer
     [not found] <mailman.2559.1372339138.22516.help-gnu-emacs@gnu.org>
2013-06-27 15:33 ` Emacs Lisp Question Barry Margolin
  -- strict thread matches above, loose matches on Subject: below --
2013-06-27 13:11 drain
2013-06-27 13:25 ` Thorsten Jolitz
2011-02-06 23:19 Emacs lisp question Ben
2011-02-07  1:38 ` Barry Margolin
2011-02-06 23:04 Ben Key
2011-02-07  0:49 ` Perry Smith
2011-02-07  1:05 ` Drew Adams
2011-02-07  1:30   ` Ben Key
2009-06-27 13:08 Emacs & Lisp question Ben Badgley
     [not found] <mailman.1371.1246077688.2239.help-gnu-emacs@gnu.org>
2009-06-27  5:52 ` Tim X
2009-06-27 10:19 ` Richard Riley
2009-06-26 23:05 Ben Badgley
2009-06-27 17:40 ` Johan Bockgård
     [not found] <mailman.303.1073667340.928.help-gnu-emacs@gnu.org>
2004-01-09 16:48 ` Emacs " Paolo Gianrossi
2004-01-09 15:55 Gian Uberto Lauri
     [not found] <mailman.669.1061546874.29551.help-gnu-emacs@gnu.org>
2003-08-22 11:17 ` Emacs LISP Question Klaus Zeitler
2003-08-20 16:04 Yakov Nekritch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=barmar-81D3F5.12051618042016@88-209-239-213.giganet.hu \
    --to=barmar@alum.mit.edu \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.