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

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

RE: [h-e-w] problem with save-excursion


From: Underwood, Jonathan
Subject: RE: [h-e-w] problem with save-excursion
Date: Mon, 29 Jul 2002 00:29:03 -0400

Actually, on a slightly related note, I use the following code to run the
code indenting program "indent" on the file in the current buffer, saving
the file before hand and reverting to the indented file after the indent
program has done its work. However i've not yet found a way to keep the
point in the same place in the file. This may be asking too much, since the
file is modified by an external program, but i just wondered if anyone had
any ideas..

;; custom function to indent code using external indent program
(defvar indent-program "indent"
  "External program used for indentation of C source code (usually GNU
indent).")

(defvar indent-args nil
  "Command line arguments passed to indent. See man indent for a list. Note
that
any arguments in ~\.indent.pro will be passed to indent automatically.")

(defun indent-c-buffer ()
  "Indents the current buffer using indent-program. Saves prior to
running indent."
  (interactive)
  (save-buffer)
  (shell-command (concat indent-program " " 
                         indent-args " " 
                         (shell-quote-argument buffer-file-name)))
  (revert-buffer t t)
  (recenter)
  (setq srcbuf (current-buffer))
  (set-buffer "*Shell Command Output*") ;check output for errors
  (if (not (eq (buffer-substring 1 7) "indent"))
      (display-buffer "*Shell Command Output*")) ;display errors if any
  (set-buffer srcbuf)
  (message (concat (file-name-nondirectory buffer-file-name) "saved and
indented."))
)


TIA

jonathan.

> -----Original Message-----
> From: Richard M. Heiberger [mailto:address@hidden
> Sent: July 29, 2002 12:15 AM
> To: address@hidden; Mike Krell
> Subject: Re: [h-e-w] problem with save-excursion
> 
> 
> .shell-command-on-region is an interactive compiled Lisp 
> function in `simple'.
> (shell-command-on-region START END COMMAND &optional 
> OUTPUT-BUFFER REPLACE ERROR-BUFFER)
> 
> 
> The second `t' in your argument list is an instruction to 
> REPLACE the the input
> If REPLACE, the optional fifth argument, is non-nil, that means insert
> the output in place of text from START to END, putting point and mark
> around it.
> 
> change it to `nil'
> 



reply via email to

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