all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: compile-command customisation
@ 2005-02-24  9:19 Daniel Wright
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Wright @ 2005-02-24  9:19 UTC (permalink / raw)


Thien-Thi Nguyen <ttn@glug.org> writes:
>Daniel Wright <daniel.d.wright@gmail.com> writes:
>
>> how it could be done better :)
>
>some standard tips:
>
>(if CONDITION (progn EXP ...))
>=> (when CONDITION EXP ...)
>
>(unless CONDITION (progn EXP ...))
>=> (unless CONDITION EXP ...)
>
>you can lift `file-name-sans-extension', like so:
>
>(... (file-name-sans-extension file)
>... (file-name-sans-extension file) ...)
>=> (let ((fn-noext (file-name-sans-extension file)))
>    (... fn-noext
>     ... fn-noext ...))
>
>generally, these transforms do not change your algorithm,
>so it is only better in the sense that it is more easy to
>read.  improving the algorithm is your sack of joy to haul.

Thanks for the help! It really does make it a lot easier to read. It
seemed necessary to use "let*" so that file-noext gets evaluated
correctly:

...
(let* ((count 0) (file (file-name-nondirectory buffer-file-name))
     (file-noext (file-name-sans-extension file)))
...

After reading the reply from Kevin Rodgers, I'll leave the improvement
of this algorithm: I'm sure there are plenty of others to improve.. ;)

Thanks again!
Daniel

^ permalink raw reply	[flat|nested] 12+ messages in thread
[parent not found: <mailman.1420.1109237398.32256.help-gnu-emacs@gnu.org>]
[parent not found: <421ce346.7d020262.679d.ffff9321SMTPIN_ADDED@mx.gmail.com>]
* Re: compile-command customisation
@ 2005-02-24  8:59 Daniel Wright
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Wright @ 2005-02-24  8:59 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:
>Never call `find-file' from elisp.
>Instead, use (with-current-buffer (find-file-noselect "Makefile") ...).
>
>      Stefan

Thanks a lot for the tip! It did seem a bit over zealous to hop around
from file to file. But the way you use "never" makes me think, that it
is more than just common sense - is there another reason too?

The emacs lisp manual (i finally looked at it) suggests copying the
the contents of the file to an empty buffer (with
"insert-file-contents"), it seems a good idea in this case - i could
then just search that. What do you think?

Thanks again!
Daniel

^ permalink raw reply	[flat|nested] 12+ messages in thread
[parent not found: <mailman.1248.1109165001.32256.help-gnu-emacs@gnu.org>]
* compile-command customisation
@ 2005-02-23 12:51 Daniel Wright
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Wright @ 2005-02-23 12:51 UTC (permalink / raw)


Hi all,
Sorry to flog a dead horse: this subject has been discussed recently.
But I found the compile-command customisation so fantastic, it took me
to a new level of emacs power, (from the emacs wiki):

(add-hook 'c-mode-common-hook
	  (lambda ()
	    (unless (file-exists-p "Makefile")
	      (set (make-local-variable 'compile-command)
		   (let ((file (file-name-nondirectory buffer-file-name)))
		     (concat "gcc -g -Wall -W -o " (file-name-sans-extension file)
			     " " file))))))

But let's say you want to write a little test c/c++ program that you
don't want to include in your Makefile, but still have in the
project's directory (i.e. there is a Makefile there). Then the above
version of the function won't work, so I've playing with the following
(which searches through the Makefile):

(add-hook 'c-mode-common-hook
	  (lambda ()
	    (let ((count 0) (file (file-name-nondirectory buffer-file-name)))
	      (if (file-exists-p "Makefile")
		  (progn
		    (find-file "Makefile")
		    (while (search-forward (file-name-sans-extension file) nil t count)
		      (setq count (1+ count)))
		    (find-file file)))
	      (unless (> count 1)
		(progn
		  (set (make-local-variable 'compile-command)
		       (concat "gcc -g -Wall -W -o " (file-name-sans-extension file)
			       " " file)))))))

I was wondering what you all think. I started with emacs lisp this
week, so I don't mind if you tell me how bad it is, as long as you
tell us how it could be done better :)

Cheers,
Daniel

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-02-27  2:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-24  9:19 compile-command customisation Daniel Wright
     [not found] <mailman.1420.1109237398.32256.help-gnu-emacs@gnu.org>
2005-02-25 13:49 ` Stefan Monnier
2005-02-26 12:02   ` Daniel Wright
     [not found] <421ce346.7d020262.679d.ffff9321SMTPIN_ADDED@mx.gmail.com>
2005-02-24  9:41 ` Daniel Wright
  -- strict thread matches above, loose matches on Subject: below --
2005-02-24  8:59 Daniel Wright
     [not found] <mailman.1248.1109165001.32256.help-gnu-emacs@gnu.org>
2005-02-23 14:51 ` Stefan Monnier
2005-02-26 22:13   ` Steinar Børmer
2005-02-26 22:23   ` Steinar Børmer
2005-02-27  2:43     ` Stefan Monnier
2005-02-23 15:44 ` Thien-Thi Nguyen
2005-02-23 15:48 ` Kevin Rodgers
2005-02-23 12:51 Daniel Wright

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.