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

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

Re: How to apply (multi file) patches conveniently


From: Michael Heerdegen
Subject: Re: How to apply (multi file) patches conveniently
Date: Tue, 07 Feb 2017 21:22:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

> It depends on what is at the beginning of the buffer, and what is
> after the patch itself.  With some text there, Patch could become
> utterly confused.  It does know about a typical beginning of an email
> message, but buffer contents could be anything...
>
> So I really recommend to mark the patch.

Ok, but can in real-life situations happen things worse then "patch"
saying it could not apply the patch?  Did it ever happen to you that it
applied something wrong?


FWIW, I wrote this:

#+begin_src emacs-lisp
(defun my-gnus-patch-from-article ()
  (interactive)
  (with-current-buffer gnus-article-buffer
    (shell-command-on-region
     (if (use-region-p) (region-beginning) (point-min))
     (if (use-region-p) (region-end)       (point-max))
     (format "patch -d '%s' -p1"
             (let* ((insert-default-directory nil)
                    (input (read-directory-name (format "Dir (default %s): "
                                                        (or source-directory 
default-directory)))))
               (if (string= input "")
                   (expand-file-name (or source-directory
                   default-directory)) input))))))

(define-key gnus-article-mode-map [?P] #'my-gnus-patch-from-article)
(define-key gnus-summary-mode-map [?P] #'my-gnus-patch-from-article)
#+end_src

so I can mark a region, but don't have to.


Thanks,

Michael.



reply via email to

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