From e292c0973cf7a92819d312ea8a828b67e6adf1ab Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Tue, 12 Jun 2018 18:41:46 -0400 Subject: [PATCH 1/7] Fix #'fun handling inside `labels' (Bug#31792) * lisp/emacs-lisp/cl.el (labels): Apply the equivalent of the cl-labels change from 2015-01-16 "* lisp/emacs-lisp/cl-macs.el: Fix last change". * test/lisp/emacs-lisp/cl-tests.el (labels-function-quoting): New test. * lisp/emacs-lisp/cl-macs.el (cl-flet, cl-labels): Improve docstring, link to relevant manual page. * doc/misc/cl.texi (Function Bindings): Don't imply that function cells of symbols are modified by cl-flet. Don't claim that cl-flet or cl-labels affect references of the form (quote FUNC). --- doc/misc/cl.texi | 23 +++++++++------------ lisp/emacs-lisp/cl-macs.el | 17 +++++++++++----- lisp/emacs-lisp/cl.el | 7 +++++-- test/lisp/emacs-lisp/cl-tests.el | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 test/lisp/emacs-lisp/cl-tests.el diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index bf85b00e937..553b935b1ef 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi @@ -1299,17 +1299,18 @@ These forms make @code{let}-like bindings to functions instead of variables. @defmac cl-flet (bindings@dots{}) forms@dots{} -This form establishes @code{let}-style bindings on the function -cells of symbols rather than on the value cells. Each @var{binding} -must be a list of the form @samp{(@var{name} @var{arglist} -@var{forms}@dots{})}, which defines a function exactly as if -it were a @code{cl-defun} form. The function @var{name} is defined -accordingly but only within the body of the @code{cl-flet}, hiding any external -definition if applicable. +This form establishes @code{let}-style bindings for functions rather +than values. Each @var{binding} must be a list of the form +@samp{(@var{name} @var{arglist} @var{body}@dots{})}. Within +@var{forms}, any reference to the function @var{name} uses the local +definition instead of the global one. + +A ``reference'' to a function name is either a call to that function, +or a use of its name quoted by @code{function} to be passed on to, +say, @code{mapcar}. The bindings are lexical in scope. This means that all references to -the named functions must appear physically within the body of the -@code{cl-flet} form. +the named functions must appear physically within @var{forms}. Functions defined by @code{cl-flet} may use the full Common Lisp argument notation supported by @code{cl-defun}; also, the function @@ -1336,10 +1337,6 @@ functions must appear physically within the body of the the functions themselves. Thus, @code{cl-labels} can define local recursive functions, or mutually-recursive sets of functions. -A ``reference'' to a function name is either a call to that -function, or a use of its name quoted by @code{quote} or -@code{function} to be passed on to, say, @code{mapcar}. - Note that the @file{cl.el} version of this macro behaves slightly differently. @xref{Obsolete Macros}. @end defmac diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 9c47ceae18e..0854e665b9b 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -1964,13 +1964,16 @@ a `let' form, except that the list of symbols can be computed at run-time." ;;;###autoload (defmacro cl-flet (bindings &rest body) "Make local function definitions. -Like `cl-labels' but the definitions are not recursive. -Each binding can take the form (FUNC EXP) where +Each definition can take the form (FUNC EXP) where FUNC is the function name, and EXP is an expression that returns the function value to which it should be bound, or it can take the more common form \(FUNC ARGLIST BODY...) which is a shorthand for (FUNC (lambda ARGLIST BODY)). +FUNC is defined only within FORM, not BODY, so you can't write +recursive function definitions. Use `cl-labels' for that. See +info node `(cl) Function Bindings' for details. + \(fn ((FUNC ARGLIST BODY...) ...) FORM...)" (declare (indent 1) (debug ((&rest (cl-defun)) cl-declarations body))) (let ((binds ()) (newenv macroexpand-all-environment)) @@ -2012,9 +2015,13 @@ Like `cl-flet' but the definitions can refer to previous ones. ;;;###autoload (defmacro cl-labels (bindings &rest body) - "Make temporary function bindings. -The bindings can be recursive and the scoping is lexical, but capturing them -in closures will only work if `lexical-binding' is in use. + "Make local (recursive) function definitions. +Each definition can take the form (FUNC ARGLIST BODY...) where +FUNC is the function name, ARGLIST its arguments, and BODY the +forms of the function body. FUNC is defined in any BODY, as well +as FORM, so you can write recursive and mutually recursive +function definitions. See info node `(cl) Function Bindings' for +details. \(fn ((FUNC ARGLIST BODY...) ...) FORM...)" (declare (indent 1) (debug cl-flet)) diff --git a/lisp/emacs-lisp/cl.el b/lisp/emacs-lisp/cl.el index d53c8e0bbcf..f6643158d2d 100644 --- a/lisp/emacs-lisp/cl.el +++ b/lisp/emacs-lisp/cl.el @@ -466,9 +466,12 @@ rather than relying on `lexical-binding'." (push var sets) (push (cons (car binding) `(lambda (&rest cl-labels-args) - (cl-list* 'funcall ',var - cl-labels-args))) + (if (eq (car cl-labels-args) cl--labels-magic) + (list cl--labels-magic ',var) + (cl-list* 'funcall ',var cl-labels-args)))) newenv))) + ;; `lexical-let' adds `cl--function-convert' (which calls + ;; `cl--labels-convert') as a macroexpander for `function'. (macroexpand-all `(lexical-let ,vars (setq ,@sets) ,@body) newenv))) ;; Generalized variables are provided by gv.el, but some details are diff --git a/test/lisp/emacs-lisp/cl-tests.el b/test/lisp/emacs-lisp/cl-tests.el new file mode 100644 index 00000000000..b673822cd9a --- /dev/null +++ b/test/lisp/emacs-lisp/cl-tests.el @@ -0,0 +1,35 @@ +;;; cl-tests.el --- tests for emacs-lisp/cl.el -*- lexical-binding:t -*- + +;; Copyright (C) 2018 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; This program is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation, either version 3 of the +;; License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see `https://www.gnu.org/licenses/'. + +;;; Commentary: + +;;; Code: + +(require 'cl) +(require 'ert) + + + +(ert-deftest labels-function-quoting () + "Test that #'foo does the right thing in `labels'." ; Bug#31792. + (should (eq (funcall (labels ((foo () t)) + #'foo)) + t))) + +;;; cl-tests.el ends here From d289e7e38a4769fad8a3390721f75d996d0e07b4 Mon Sep 17 00:00:00 2001 From: Tak Kunihiro Date: Wed, 20 Jun 2018 09:27:50 +0200 Subject: [PATCH 2/7] Fix bug of 'mouse-drag-and-drop-region' to detect edges of region (Bug#31905) * lisp/mouse.el (mouse-drag-and-drop-region): Detect both the beginning and the end of character of region during dragging text. --- lisp/mouse.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/mouse.el b/lisp/mouse.el index 5c9056fb43d..f749d12054b 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -2515,9 +2515,9 @@ is copied instead of being cut." (setq drag-but-negligible (and (eq (overlay-buffer mouse-drag-and-drop-overlay) buffer-to-paste) - (< (overlay-start mouse-drag-and-drop-overlay) + (<= (overlay-start mouse-drag-and-drop-overlay) point-to-paste) - (< point-to-paste + (<= point-to-paste (overlay-end mouse-drag-and-drop-overlay))))) ;; Show a tooltip. From 40e1db8ccd1239fc7da5ccd3f5f79017b2b44afc Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 20 Jun 2018 08:40:51 -0400 Subject: [PATCH 3/7] Change index of ";" to better reflect it's usage (Bug#31623) * doc/lispref/objects.texi (Comments): "; for commenting" fits better with the following text about how a semicolon begins a comment. Also mention that only unescaped semicolons start a comment. --- doc/lispref/objects.texi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index c7e751cbd8c..b8cae49027c 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi @@ -109,15 +109,15 @@ not be evaluated later. @xref{Input Functions}, for a description of @node Comments @section Comments @cindex comments -@cindex @samp{;} in comment +@cindex @samp{;} for commenting - A @dfn{comment} is text that is written in a program only for the sake -of humans that read the program, and that has no effect on the meaning -of the program. In Lisp, a semicolon (@samp{;}) starts a comment if it -is not within a string or character constant. The comment continues to -the end of line. The Lisp reader discards comments; they do not become -part of the Lisp objects which represent the program within the Lisp -system. + A @dfn{comment} is text that is written in a program only for the +sake of humans that read the program, and that has no effect on the +meaning of the program. In Lisp, an unescaped semicolon (@samp{;}) +starts a comment if it is not within a string or character constant. +The comment continues to the end of line. The Lisp reader discards +comments; they do not become part of the Lisp objects which represent +the program within the Lisp system. The @samp{#@@@var{count}} construct, which skips the next @var{count} characters, is useful for program-generated comments containing binary From 3d2e3dc1ca8ee7226668ab5bbd35061d37bcbbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Sun, 9 Apr 2017 11:06:44 +0200 Subject: [PATCH 4/7] Change name of `seqp' argument (Bug#26411) * lisp/emacs-lisp/seq.el (seqp): Change argument name. * doc/lispref/sequences.texi: Update the documentation for seqp. --- doc/lispref/sequences.texi | 4 ++-- lisp/emacs-lisp/seq.el | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index f347cd9e980..76a4a468880 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -474,8 +474,8 @@ built-in sequence types, @code{seq-length} behaves like @code{length}. @xref{Definition of length}. @end defun -@defun seqp sequence - This function returns non-@code{nil} if @var{sequence} is a sequence +@defun seqp object + This function returns non-@code{nil} if @var{object} is a sequence (a list or array), or any additional type of sequence defined via @file{seq.el} generic functions. diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 5d6ab7e057f..b40c424e303 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -127,9 +127,9 @@ the sequence, and its index within the sequence." (setq index (1+ index))) sequence))) -(cl-defgeneric seqp (sequence) - "Return non-nil if SEQUENCE is a sequence, nil otherwise." - (sequencep sequence)) +(cl-defgeneric seqp (object) + "Return non-nil if OBJECT is a sequence, nil otherwise." + (sequencep object)) (cl-defgeneric seq-copy (sequence) "Return a shallow copy of SEQUENCE." From d22b8d1ad12c69a2c97bb9f4c9eb4316df13429e Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Fri, 22 Jun 2018 09:59:47 +0200 Subject: [PATCH 5/7] Adjust for scaling for mode-line popup menus (Bug#31880) * src/xmenu.c (menu_position_func) [HAVE_GTK3]: Take scaling into account when calculating screen size. --- src/xmenu.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/xmenu.c b/src/xmenu.c index e7ef31ac564..d285e568b03 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -1162,11 +1162,17 @@ menu_position_func (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer GtkRequisition req; int max_x = -1; int max_y = -1; +#ifdef HAVE_GTK3 + int scale; +#endif Lisp_Object frame, workarea; XSETFRAME (frame, data->f); +#ifdef HAVE_GTK3 + scale = xg_get_scale (data->f); +#endif /* TODO: Get the monitor workarea directly without calculating other items in x-display-monitor-attributes-list. */ workarea = call3 (Qframe_monitor_workarea, @@ -1192,11 +1198,20 @@ menu_position_func (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer max_y = x_display_pixel_height (dpyinfo); } + /* frame-monitor-workarea and {x,y}_display_pixel_width/height all + return device pixels, but GTK wants scaled pixels. The positions + passed in via data were already scaled for us. */ +#ifdef HAVE_GTK3 + max_x /= scale; + max_y /= scale; +#endif *x = data->x; *y = data->y; /* Check if there is room for the menu. If not, adjust x/y so that - the menu is fully visible. */ + the menu is fully visible. gtk_widget_get_preferred_size returns + scaled pixels, so there is no need to apply the scaling + factor. */ gtk_widget_get_preferred_size (GTK_WIDGET (menu), NULL, &req); if (data->x + req.width > max_x) *x -= data->x + req.width - max_x; From d6aa55e2b48d56bf9a2cd25176029b6fb80a80b2 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 22 Jun 2018 15:57:47 +0300 Subject: [PATCH 6/7] Avoid segfaults in replace-buffer-contents with large buffers * src/editfns.c (Freplace_buffer_contents): Don't release malloc'ed memory as long as we are using it. (Bug#31888) --- src/editfns.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/editfns.c b/src/editfns.c index fc5b6c117f5..d15ae59029d 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3215,7 +3215,6 @@ buffer stay intact. */) /* Since we didn’t define EARLY_ABORT, we should never abort early. */ eassert (! early_abort); - SAFE_FREE (); Fundo_boundary (); ptrdiff_t count = SPECPDL_INDEX (); @@ -3261,8 +3260,10 @@ buffer stay intact. */) --i; --j; } + unbind_to (count, Qnil); + SAFE_FREE (); - return unbind_to (count, Qnil); + return Qnil; } static void From 5cb3991a4f78b39a2c95b22a5159ae3ba779397e Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 22 Jun 2018 21:25:55 +0300 Subject: [PATCH 7/7] Fix a typo in emacs-lisp-intro.texi * doc/lispintro/emacs-lisp-intro.texi (kill-ring-yank-pointer): Add a missing quote. Reported by Jean-Christophe Helary in emacs-devel. --- doc/lispintro/emacs-lisp-intro.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/lispintro/emacs-lisp-intro.texi b/doc/lispintro/emacs-lisp-intro.texi index aad572623a3..cc940e5cbdc 100644 --- a/doc/lispintro/emacs-lisp-intro.texi +++ b/doc/lispintro/emacs-lisp-intro.texi @@ -10049,7 +10049,7 @@ kill-ring kill-ring-yank-pointer | | | | | --> "yet more text" | | - | --> "a different piece of text + | --> "a different piece of text" | --> "some text" @end group