From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Emacs lisp question Date: Mon, 18 Apr 2016 12:05:16 -0400 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1464881382 12820 80.91.229.3 (2 Jun 2016 15:29:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Jun 2016 15:29:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 02 17:29:40 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1b8UZ0-0002HG-9Z for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jun 2016 17:29:38 +0200 Original-Received: from localhost ([::1]:48035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8UYz-0001vg-F1 for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jun 2016 11:29:37 -0400 Original-Path: usenet.stanford.edu!goblin3!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!barmar.motzarella.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 57 Injection-Info: barmar.motzarella.org; posting-host="2be9e9f5dd9af768b8861af71b85fc28"; logging-data="14553"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Of+1+HkN2bEcvKOVTouQg" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:DiaRwAxPoABlflR498OrWiF4JN4= Original-Xref: usenet.stanford.edu gnu.emacs.help:217499 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110177 Archived-At: In article , Matthias Pfeifer 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 ***