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

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

Re: how to get around deprecated function


From: John Mastro
Subject: Re: how to get around deprecated function
Date: Tue, 5 May 2015 10:13:07 -0700

Hi B. T.,

> The following related function might also benefit from some
> "subtractional betterment" in case you care to comment. This just
> appends the line where cursor (or maybe more accurately 'point')
> happens to be to the *scratch* buffer. I know I can make beg, end
> local to function by using let instead of setq but I always
> re-initialize beg and end:
>
>
> (defun append-line-to-starscratch ();; M-x asl
> (interactive)
> (move-beginning-of-line nil)
> (set-mark-command nil) (setq beg (point))
> (move-end-of-line nil) (setq end (point))
> (kill-ring-save beg end)
> (with-current-buffer "*scratch*"
>      (end-of-buffer) (insert "\n")
>      (yank)))
>

Here's a simplified version, which also adds the feature that it will
use the active region, if any, or the current line otherwise.

    (defun append-to-starscratch (beg end)
      (interactive
       (if (use-region-p)
           (list (region-beginning) (region-end))
         (list (line-beginning-position) (line-end-position))))
      (let ((str (buffer-substring beg end)))
        (with-current-buffer (get-buffer-create "*scratch*")
          (goto-char (point-max))
          (insert "\n" str))))

-- 
john



reply via email to

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