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

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

Re: simple function to prepend a string to a file


From: harven
Subject: Re: simple function to prepend a string to a file
Date: Fri, 17 Apr 2009 16:10:39 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin)

ken <gebser@mousecar.com> writes:

> Often I want to put the string "<!-- -*- coding: utf-8; -*- -->\n" at
> the top of the current buffer.  However, I don't want to lose my place
> (the point) or any defined region.  Optimally, such a function would
> know the mode of the current buffer and enclose the string in the
> mode-appropriate comment characters.  Is there such a function?  If not
> how would one code it?
>
> Thanks for your solutions.

The following seems to work.

(defun my-header ()
  "put a commented header at the beginning of the buffer"
  (interactive)
  (save-excursion
    (beginning-of-buffer)
    (let ((start (point)))
      (insert "-*- coding: utf-8; -*-")
      (comment-region start (point))
      (newline))))



reply via email to

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