all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Vitalie Spinu <spinuvit@gmail.com>
Cc: 28039@debbugs.gnu.org, npostavs@users.sourceforge.net
Subject: bug#28039: 26.0.50; Ses copy-region-as-kill advice assumes non-nil beg end arguments
Date: Sat, 12 Aug 2017 13:25:33 +0900	[thread overview]
Message-ID: <87y3qp1kg2.fsf@calancha-pc> (raw)
In-Reply-To: <87r2wjl6gy.fsf@galago> (Vitalie Spinu's message of "Thu, 10 Aug 2017 18:42:37 +0200")

Vitalie Spinu <spinuvit@gmail.com> writes:


> Once ses is loaded I am getting the following error on kill in magit buffers:
>
> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
>   ses--advice-copy-region-as-kill(#[770 "\
>   apply(ses--advice-copy-region-as-kill #[770 
>   copy-region-as-kill(nil nil region)
>   magit-copy-buffer-revision()
>   funcall-interactively(magit-copy-buffer-revision)
>   #<subr call-interactively>(magit-copy-buffer-revision nil nil)
>   apply(#<subr call-interactively> magit-copy-buffer-revision (nil nil))
>   call-interactively@ido-cr+-record-current-command(#<subr call-interactively> magit-copy-buffer-revision nil nil)
>   apply(call-interactively@ido-cr+-record-current-command #<subr call-interactively> (magit-copy-buffer-revision nil nil))
>   call-interactively(magit-copy-buffer-revision nil nil)
>   command-execute(magit-copy-buffer-revision)
>
>
> Magit calls (copy-region-as-kill nil nil 'region). According to the doc first
> two args should be ignored when 'region is passed. So I would assume it's the
> bug in `ses--advice-copy-region-as-kill` then.
Thank you for the report.
I've noticed that `copy-region-as-kill' also needs `natnump' checks for
BEG, END.
How about th following patch?

--8<-----------------------------cut here---------------start------------->8---
commit 019b5ebf09e69593b0e50ba2ce53501b83331ecc
Author: Tino Calancha <tino.calancha@gmail.com>
Date:   Sat Aug 12 13:24:35 2017 +0900

    copy-region-as-kill: Check types of BEG, END
    
    * lisp/ses.el (ses--advice-copy-region-as-kill): Check that BEG, END
    are non-negative integers (Bug#28039).
    (copy-region-as-kill): Same.
    * test/lisp/simple-tests.el (simple-test-bug28039): Add test.

diff --git a/lisp/ses.el b/lisp/ses.el
index 8c5ff2136f..676c36a5b7 100644
--- a/lisp/ses.el
+++ b/lisp/ses.el
@@ -3052,14 +3052,12 @@ ses--advice-copy-region-as-kill
 
 This advice also includes some SES-specific code because otherwise it's too
 hard to override how mouse-1 works."
-  (when (> beg end)
-    (let ((temp beg))
-      (setq beg end
-	    end temp)))
-  (if (not (and (derived-mode-p 'ses-mode)
-		(eq (get-text-property beg 'read-only) 'ses)
-		(eq (get-text-property (1- end) 'read-only) 'ses)))
+  (if (or (not (or (natnump beg) (natnump end)))
+          (not (and (derived-mode-p 'ses-mode)
+		    (eq (get-text-property beg 'read-only) 'ses)
+		    (eq (get-text-property (1- end) 'read-only) 'ses))))
       (apply crak-fun beg end args) ; Normal copy-region-as-kill.
+    (when (> beg end) (cl-rotatef beg end))
     (kill-new (ses-copy-region beg end))
     (if transient-mark-mode
 	(setq deactivate-mark t))
diff --git a/lisp/simple.el b/lisp/simple.el
index 933ffc55a6..170e612918 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -4552,7 +4552,7 @@ copy-region-as-kill
                  (funcall region-extract-function nil)
                (filter-buffer-substring beg end))))
   (if (eq last-command 'kill-region)
-        (kill-append str (< end beg))
+        (kill-append str (and (natnump beg) (natnump end) (< end beg)))
       (kill-new str)))
   (setq deactivate-mark t)
   nil)
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index ad7aee1db1..27e607ec13 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -497,5 +497,16 @@ simple-test-undo-with-switched-buffer
       (should (equal (line-number-at-pos 5) 3))
       (should (equal (line-number-at-pos 7) 4)))))
 
+(ert-deftest simple-test-bug28039 ()
+  "Test for http://debbugs.gnu.org/28039 ."
+  (with-temp-buffer
+    (insert "123456789abc")
+    (kill-region 1 10)
+    (set-mark (point))
+    (goto-char 1)
+    (copy-region-as-kill nil nil t)
+    (should (equal "abc" (current-kill 0)))))
+
+
 (provide 'simple-test)
 ;;; simple-test.el ends here
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-08-12 built on calancha-pc
Repository revision: e3ed43f4ac667d39fffcc48cfbe97b074f9aa5c7





  reply	other threads:[~2017-08-12  4:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-10 16:42 bug#28039: 26.0.50; Ses copy-region-as-kill advice assumes non-nil beg end arguments Vitalie Spinu
2017-08-12  4:25 ` Tino Calancha [this message]
2017-12-17  4:52 ` Óscar Fuentes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y3qp1kg2.fsf@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=28039@debbugs.gnu.org \
    --cc=npostavs@users.sourceforge.net \
    --cc=spinuvit@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.