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

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

Re: How to change and save a read-only file?


From: Emanuel Berg
Subject: Re: How to change and save a read-only file?
Date: Fri, 19 Jul 2013 14:36:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:

> That looks pretty standard to me. But more important, it works
> great!

I tried to improve the function even more, because I noticed, when
there was a region in the original buffer, and I wanted to do
something on that region, when I stroke the `su-edit', the region
disapeared. So, I made changes to the function (code last). It
works, but with one detail missing: I get the region as desired in
the new buffer, but for some reason, *the region doesn't
show*. The highlight isn't there. But if I strike `write-region'
or whatever, I can confirm that the region is there as it
should. Any ideas?

I tried both with set-mark, and set-mark-command, with the same
result.

(defun su-edit ()
  "Edit the current buffer file as superuser."
  (interactive)
  (let((window-start (window-start))
       (point (point))
       (pres-reg-beg (if (use-region-p) (region-beginning) nil)))
    (find-alternate-file (format "/sudo::%s" (buffer-file-name)))
    (message (format "The variable is %d." pres-reg-beg))
    (if pres-reg-beg (set-mark pres-reg-beg)) ; same: set-mark-command
    (goto-char point)
    (set-window-start nil window-start) )) ; nil - the selected window

-- 
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573


reply via email to

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