commit 5a024b72c50129cc429bc4b8b18b8c08f3f6b430 (HEAD, refs/remotes/origin/master) Author: Alexander Gramiak Date: Tue May 21 14:58:59 2019 -0600 * src/xfont.c (xfont_draw): Allocate the XChar2b array (Bug#35814) diff --git a/src/xfont.c b/src/xfont.c index a402f77063..81808e7a62 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -1047,11 +1047,16 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y, } else { - const unsigned code = s->char2b[from]; - const XChar2b char2b = { .byte1 = code >> 8, - .byte2 = code & 0xFF }; + USE_SAFE_ALLOCA; + const unsigned *code = s->char2b + from; + XChar2b *char2b; + SAFE_NALLOCA (char2b, 1, len); + for (int i = 0; i < len; ++i) + char2b[i] = (XChar2b) { .byte1 = code[i] >> 8, + .byte2 = code[i] & 0xFF }; XDrawImageString16 (display, FRAME_X_DRAWABLE (s->f), - gc, x, y, &char2b, len); + gc, x, y, char2b, len); + SAFE_FREE (); } } else @@ -1067,11 +1072,16 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y, } else { - const unsigned code = s->char2b[from]; - const XChar2b char2b = { .byte1 = code >> 8, - .byte2 = code & 0xFF }; + USE_SAFE_ALLOCA; + const unsigned *code = s->char2b + from; + XChar2b *char2b; + SAFE_NALLOCA (char2b, 1, len); + for (int i = 0; i < len; ++i) + char2b[i] = (XChar2b) { .byte1 = code[i] >> 8, + .byte2 = code[i] & 0xFF }; XDrawString16 (display, FRAME_X_DRAWABLE (s->f), - gc, x, y, &char2b, len); + gc, x, y, char2b, len); + SAFE_FREE (); } } unblock_input (); commit 9624f609493da7c08016ba00d6895bad0fe26a0e Author: Alan Third Date: Tue Apr 2 21:49:36 2019 +0100 Fix some deprecation notices on macOS 10.14 * src/nsimage.m ([EmacsImage setXBMColor:]): Replace colorSpaceName code. * src/nsmenu.m ([EmacsDialogPanel initWithContentRect:styleMask:]): Remove reference to oneShot. * src/nsterm.h (ns_enable_screen_updates): Remove function prototype. (NSPasteboardTypeString): (NSPasteboardTypeTabularText): (NSControlStateValueOn): (NSControlStateValueOff): (NSBezelStyleRounded): (NSPasteboardTypeURL): Define new names and replace all callers. * src/nsterm.m ([EmacsColor colorUsingDefaultColorSpace]): Replace calls to colorUsingColorSpaceName on macOS > 10.7. ([EmacsView performDragOperation:]): Add FIXME about deprecation. (ns_disable_screen_updates): (ns_enable_screen_updates): Remove functions and all callers. (disable_screen_updates_count): Remove variable. * src/macfont.m (macfont_draw): Use CGContext instead of graphicsPort on macOS >= 10.10 diff --git a/src/macfont.m b/src/macfont.m index d69af67981..f825e6291d 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -2818,7 +2818,18 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no } } - context = [[NSGraphicsContext currentContext] graphicsPort]; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000 + if ([[NSGraphicsContext currentContext] respondsToSelector:@selector(CGContext)]) +#endif + context = [[NSGraphicsContext currentContext] CGContext]; +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000 + else +#endif +#endif +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101000 + context = [[NSGraphicsContext currentContext] graphicsPort]; +#endif CGContextSaveGState (context); if (!CGRectIsNull (background_rect)) diff --git a/src/nsimage.m b/src/nsimage.m index 33236c48d4..0249d22aca 100644 --- a/src/nsimage.m +++ b/src/nsimage.m @@ -313,8 +313,8 @@ - (instancetype)setXBMColor: (NSColor *)color if (bmRep == nil || color == nil) return self; - if ([color colorSpaceName] != NSCalibratedRGBColorSpace) - rgbColor = [color colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; + if ([color colorSpace] != [NSColorSpace deviceRGBColorSpace]) + rgbColor = [color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]]; else rgbColor = color; diff --git a/src/nsmenu.m b/src/nsmenu.m index fd1323344b..3fe06cda02 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m @@ -668,9 +668,9 @@ - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr /* Draw radio buttons and tickboxes. */ if (wv->selected && (wv->button_type == BUTTON_TYPE_TOGGLE || wv->button_type == BUTTON_TYPE_RADIO)) - [item setState: NSOnState]; + [item setState: NSControlStateValueOn]; else - [item setState: NSOffState]; + [item setState: NSControlStateValueOff]; [item setTag: (NSInteger)wv->call_data]; } @@ -1594,7 +1594,7 @@ - (instancetype)initWithContentRect: (NSRect)contentRect styleMask: (NSWindowSty [cell setBordered: NO]; [cell setEnabled: NO]; [cell setCellAttribute: NSCellIsInsetButton to: 8]; - [cell setBezelStyle: NSRoundedBezelStyle]; + [cell setBezelStyle: NSBezelStyleRounded]; matrix = [[NSMatrix alloc] initWithFrame: contentRect mode: NSHighlightModeMatrix @@ -1607,7 +1607,6 @@ - (instancetype)initWithContentRect: (NSRect)contentRect styleMask: (NSWindowSty [matrix autorelease]; [[self contentView] addSubview: matrix]; - [self setOneShot: YES]; [self setReleasedWhenClosed: YES]; [self setHidesOnDeactivate: YES]; return self; diff --git a/src/nsselect.m b/src/nsselect.m index cf36c869eb..b044fe6f32 100644 --- a/src/nsselect.m +++ b/src/nsselect.m @@ -57,7 +57,7 @@ Updated by Christian Limpach (chris@nice.ch) if (EQ (sym, QCLIPBOARD)) return NSPasteboardNameGeneral; if (EQ (sym, QPRIMARY)) return NXPrimaryPboard; if (EQ (sym, QSECONDARY)) return NXSecondaryPboard; - if (EQ (sym, QTEXT)) return NSStringPboardType; + if (EQ (sym, QTEXT)) return NSPasteboardTypeString; return [NSString stringWithUTF8String: SSDATA (SYMBOL_NAME (sym))]; } @@ -76,11 +76,11 @@ Updated by Christian Limpach (chris@nice.ch) return QPRIMARY; if ([t isEqualToString: NXSecondaryPboard]) return QSECONDARY; - if ([t isEqualToString: NSStringPboardType]) + if ([t isEqualToString: NSPasteboardTypeString]) return QTEXT; if ([t isEqualToString: NSFilenamesPboardType]) return QFILE_NAME; - if ([t isEqualToString: NSTabularTextPboardType]) + if ([t isEqualToString: NSPasteboardTypeTabularText]) return QTEXT; return intern ([t UTF8String]); } @@ -193,7 +193,7 @@ Updated by Christian Limpach (chris@nice.ch) else { // Used for ns-own-selection-internal. - eassert (gtype == NSStringPboardType); + eassert (gtype == NSPasteboardTypeString); [pb setString: nsStr forType: gtype]; } [nsStr release]; @@ -345,7 +345,7 @@ Updated by Christian Limpach (chris@nice.ch) } /* We only support copy of text. */ - type = NSStringPboardType; + type = NSPasteboardTypeString; target_symbol = ns_string_to_symbol (type); if (STRINGP (value)) { @@ -472,9 +472,9 @@ Updated by Christian Limpach (chris@nice.ch) [NSNumber numberWithLong:0], NSPasteboardNameGeneral, [NSNumber numberWithLong:0], NXPrimaryPboard, [NSNumber numberWithLong:0], NXSecondaryPboard, - [NSNumber numberWithLong:0], NSStringPboardType, + [NSNumber numberWithLong:0], NSPasteboardTypeString, [NSNumber numberWithLong:0], NSFilenamesPboardType, - [NSNumber numberWithLong:0], NSTabularTextPboardType, + [NSNumber numberWithLong:0], NSPasteboardTypeTabularText, nil] retain]; } diff --git a/src/nsterm.h b/src/nsterm.h index 66e1272040..1e56276ca3 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1165,10 +1165,6 @@ extern void ns_release_autorelease_pool (void *); extern const char *ns_get_defaults_value (const char *key); extern void ns_init_locale (void); -#ifdef NS_IMPL_COCOA -extern void ns_enable_screen_updates (void); -#endif - /* in nsmenu */ extern void update_frame_tool_bar (struct frame *f); extern void free_frame_tool_bar (struct frame *f); @@ -1336,4 +1332,14 @@ enum NSWindowTabbingMode /* Deprecated in macOS 10.13. */ #define NSPasteboardNameGeneral NSGeneralPboard #endif + +#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_14) +/* Deprecated in macOS 10.14. */ +#define NSPasteboardTypeString NSStringPboardType +#define NSPasteboardTypeTabularText NSTabularTextPboardType +#define NSPasteboardTypeURL NSURLPboardType +#define NSControlStateValueOn NSOnState +#define NSControlStateValueOff NSOffState +#define NSBezelStyleRounded NSRoundedBezelStyle +#endif #endif /* HAVE_NS */ diff --git a/src/nsterm.m b/src/nsterm.m index a927c5f646..0cae5e9d44 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -160,20 +160,28 @@ + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green - (NSColor *)colorUsingDefaultColorSpace { - /* FIXMES: We're checking for colorWithSRGBRed here so this will - only work in the same place as in the method above. It should - really be a check whether we're on macOS 10.7 or above. */ + /* FIXME: We're checking for colorWithSRGBRed here so this will only + work in the same place as in the method above. It should really + be a check whether we're on macOS 10.7 or above. */ #if defined (NS_IMPL_COCOA) \ && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - if (ns_use_srgb_colorspace #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 - && [NSColor respondsToSelector: - @selector(colorWithSRGBRed:green:blue:alpha:)] + if ([NSColor respondsToSelector: + @selector(colorWithSRGBRed:green:blue:alpha:)]) #endif - ) - return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]]; + { + if (ns_use_srgb_colorspace) + return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]]; + else + return [self colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]]; + } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + else #endif +#endif /* NS_IMPL_COCOA && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */ +#if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MIN_REQUIRED < 1070 return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; +#endif } @end @@ -283,9 +291,6 @@ - (NSColor *)colorUsingDefaultColorSpace static BOOL ns_fake_keydown = NO; #ifdef NS_IMPL_COCOA static BOOL ns_menu_bar_is_hidden = NO; - -/* The number of times NSDisableScreenUpdates has been called. */ -static int disable_screen_updates_count = 0; #endif /* static int debug_lock = 0; */ @@ -688,40 +693,6 @@ Free a pool and temporary objects it refers to (callable from C) } -#ifdef NS_IMPL_COCOA -/* Disabling screen updates can be used to make several actions appear - "atomic" to the end user. It seems some actions can still update - the display, though. - - When we re-enable screen updates the number of calls to - NSEnableScreenUpdates should match the number to - NSDisableScreenUpdates. - - We use these functions to prevent the user seeing a blank frame - after it has been resized. ns_set_window_size disables updates and - when redisplay completes unwind_redisplay enables them again - (bug#30699). */ - -static void -ns_disable_screen_updates (void) -{ - NSDisableScreenUpdates (); - disable_screen_updates_count++; -} - -void -ns_enable_screen_updates (void) -/* Re-enable screen updates. Called from unwind_redisplay. */ -{ - while (disable_screen_updates_count > 0) - { - NSEnableScreenUpdates (); - disable_screen_updates_count--; - } -} -#endif - - static BOOL ns_menu_bar_should_be_hidden (void) /* True, if the menu bar should be hidden. */ @@ -1779,15 +1750,6 @@ Hide the window (X11 semantics) block_input (); -#ifdef NS_IMPL_COCOA - /* To prevent showing the user a blank frame, stop updates being - flushed to the screen until after redisplay has completed. This - breaks live resize (resizing with a mouse), so don't do it if - we're in a live resize loop. */ - if (![view inLiveResize]) - ns_disable_screen_updates (); -#endif - if (pixelwise) { pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width); @@ -5459,14 +5421,14 @@ Needs to be here because ns_initialize_display_info () uses AppKit classes. NSTRACE_MSG ("Input/output types"); - ns_send_types = [[NSArray arrayWithObjects: NSStringPboardType, nil] retain]; - ns_return_types = [[NSArray arrayWithObjects: NSStringPboardType, nil] + ns_send_types = [[NSArray arrayWithObjects: NSPasteboardTypeString, nil] retain]; + ns_return_types = [[NSArray arrayWithObjects: NSPasteboardTypeString, nil] retain]; ns_drag_types = [[NSArray arrayWithObjects: - NSStringPboardType, - NSTabularTextPboardType, + NSPasteboardTypeString, + NSPasteboardTypeTabularText, NSFilenamesPboardType, - NSURLPboardType, nil] retain]; + NSPasteboardTypeURL, nil] retain]; /* If fullscreen is in init/default-frame-alist, focus isn't set right for fullscreen windows, so set this. */ @@ -8276,6 +8238,9 @@ -(BOOL)performDragOperation: (id ) sender { return NO; } + /* FIXME: NSFilenamesPboardType is deprecated in 10.14, but the + NSURL method can only handle one file at a time. Stick with the + existing code at the moment. */ else if ([type isEqualToString: NSFilenamesPboardType]) { NSArray *files; @@ -8370,8 +8335,8 @@ - (BOOL) writeSelectionToPasteboard: (NSPasteboard *)pb types: (NSArray *)types NSTRACE ("[EmacsView writeSelectionToPasteboard:types:]"); - /* We only support NSStringPboardType. */ - if ([types containsObject:NSStringPboardType] == NO) { + /* We only support NSPasteboardTypeString. */ + if ([types containsObject:NSPasteboardTypeString] == NO) { return NO; } @@ -8385,7 +8350,7 @@ - (BOOL) writeSelectionToPasteboard: (NSPasteboard *)pb types: (NSArray *)types if (! STRINGP (val)) return NO; - typesDeclared = [NSArray arrayWithObject:NSStringPboardType]; + typesDeclared = [NSArray arrayWithObject:NSPasteboardTypeString]; [pb declareTypes:typesDeclared owner:nil]; ns_string_to_pasteboard (pb, val); return YES; @@ -9047,10 +9012,12 @@ - (void)mouseDown: (NSEvent *)e last_hit_part = horizontal ? scroll_bar_before_handle : scroll_bar_above_handle; break; case NSScrollerIncrementPage: last_hit_part = horizontal ? scroll_bar_after_handle : scroll_bar_below_handle; break; +#if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MIN_REQUIRED < 1070 case NSScrollerDecrementLine: last_hit_part = horizontal ? scroll_bar_left_arrow : scroll_bar_up_arrow; break; case NSScrollerIncrementLine: last_hit_part = horizontal ? scroll_bar_right_arrow : scroll_bar_down_arrow; break; +#endif case NSScrollerKnob: last_hit_part = horizontal ? scroll_bar_horizontal_handle : scroll_bar_handle; break; case NSScrollerKnobSlot: /* GNUstep-only */ diff --git a/src/xdisp.c b/src/xdisp.c index c561ea9e36..9eed74cb98 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -13986,12 +13986,6 @@ redisplay_internal (void) #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) if (popup_activated ()) { -#ifdef NS_IMPL_COCOA - /* On macOS we may have disabled screen updates due to window - resizing. We should re-enable them so the popup can be - displayed. */ - ns_enable_screen_updates (); -#endif return; } #endif @@ -14794,12 +14788,6 @@ unwind_redisplay (void) { redisplaying_p = false; unblock_buffer_flips (); -#ifdef NS_IMPL_COCOA - /* On macOS we may have disabled screen updates due to window - resizing. When redisplay completes we want to re-enable - them. */ - ns_enable_screen_updates (); -#endif } commit cb367c8e0d4a881acf8255e1ff6bdd6442efb538 Author: Paul Eggert Date: Tue May 21 08:51:48 2019 -0700 Pacify libpng on interlaced images (Bug#35843) * src/image.c (png_set_interlace_handling) [WINDOWSNT]: New function to link. (init_png_functions): Link it. (png_load_body): Call it before calling png_read_update_info. diff --git a/src/image.c b/src/image.c index 35ca3e2d66..57b405f6db 100644 --- a/src/image.c +++ b/src/image.c @@ -5802,6 +5802,7 @@ DEF_DLL_FN (png_uint_32, png_get_valid, (png_structp, png_infop, png_uint_32)); DEF_DLL_FN (void, png_set_strip_16, (png_structp)); DEF_DLL_FN (void, png_set_expand, (png_structp)); DEF_DLL_FN (void, png_set_gray_to_rgb, (png_structp)); +DEF_DLL_FN (int, png_set_interlace_handling, (png_structp)); DEF_DLL_FN (void, png_set_background, (png_structp, png_color_16p, int, int, double)); DEF_DLL_FN (png_uint_32, png_get_bKGD, @@ -5840,6 +5841,7 @@ init_png_functions (void) LOAD_DLL_FN (library, png_set_strip_16); LOAD_DLL_FN (library, png_set_expand); LOAD_DLL_FN (library, png_set_gray_to_rgb); + LOAD_DLL_FN (library, png_set_interlace_handling); LOAD_DLL_FN (library, png_set_background); LOAD_DLL_FN (library, png_get_bKGD); LOAD_DLL_FN (library, png_read_update_info); @@ -5875,6 +5877,7 @@ init_png_functions (void) # undef png_set_background # undef png_set_expand # undef png_set_gray_to_rgb +# undef png_set_interlace_handling # undef png_set_longjmp_fn # undef png_set_read_fn # undef png_set_sig_bytes @@ -5899,6 +5902,7 @@ init_png_functions (void) # define png_set_background fn_png_set_background # define png_set_expand fn_png_set_expand # define png_set_gray_to_rgb fn_png_set_gray_to_rgb +# define png_set_interlace_handling fn_png_set_interlace_handling # define png_set_longjmp_fn fn_png_set_longjmp_fn # define png_set_read_fn fn_png_set_read_fn # define png_set_sig_bytes fn_png_set_sig_bytes @@ -6213,7 +6217,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c) } } - /* Update info structure. */ + png_set_interlace_handling (png_ptr); png_read_update_info (png_ptr, info_ptr); /* Get number of channels. Valid values are 1 for grayscale images commit 8ff7807aa7c21f80798f36829edc17d4f6c1677e Author: Paul Eggert Date: Tue May 21 08:13:04 2019 -0700 Remove time-date debugging scaffolding Problem reported by Lars Ingebrigtsen in: https://lists.gnu.org/r/emacs-devel/2019-05/msg00721.html * lisp/calendar/time-date.el (date-to-time): Use plain condition-case, not condition-case-unless-debug. diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index decb21e9c2..2c0280ccf3 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el @@ -156,7 +156,7 @@ If DATE lacks timezone information, GMT is assumed." (let ((overflow-error '(error "Specified time is not representable"))) (if (equal err overflow-error) (signal (car err) (cdr err)) - (condition-case-unless-debug err + (condition-case err (encode-time (parse-time-string (timezone-make-date-arpa-standard date))) (error commit eb2e9a2ca29f7d5e3b97709e9eca14fa5556ac63 Author: Federico Tedin Date: Tue May 14 09:16:00 2019 -0300 Use lexical-binding in tempo.el and add tests For discussion, see the following thread: https://lists.gnu.org/archive/html/emacs-devel/2019-05/msg00395.html * lisp/tempo.el: Use lexical-binding. (tempo-define-template): Expand documentation to mention `tempo-user-elements'. (tempo-local-tags, tempo-collection, tempo-dirty-collection) (tempo-marks, tempo-match-finder): Define with defvar-local. (tempo-named-insertions, tempo-region-start, tempo-region-stop): Make them automatically buffer-local. * test/lisp/tempo-tests.el: Add tests for tempo.el. diff --git a/lisp/tempo.el b/lisp/tempo.el index 28afbec0f4..e3b9c76a5b 100644 --- a/lisp/tempo.el +++ b/lisp/tempo.el @@ -1,11 +1,11 @@ -;;; tempo.el --- Flexible template insertion +;;; tempo.el --- Flexible template insertion -*- lexical-binding: t; -*- ;; Copyright (C) 1994-1995, 2001-2019 Free Software Foundation, Inc. ;; Author: David Kågedal ;; Created: 16 Feb 1994 ;; Kågedal's last version number: 1.2.4 -;; Keywords: extensions, languages, tools +;; Keywords: abbrev, extensions, languages, tools ;; This file is part of GNU Emacs. @@ -152,7 +152,7 @@ setting it to (upcase), for example.") (defvar tempo-tags nil "An association list with tags and corresponding templates.") -(defvar tempo-local-tags '((tempo-tags . nil)) +(defvar-local tempo-local-tags '((tempo-tags . nil)) "A list of locally installed tag completion lists. It is an association list where the car of every element is a symbol whose variable value is a template list. The cdr part, if non-nil, @@ -161,16 +161,16 @@ documentation for the function `tempo-complete-tag' for more info. `tempo-tags' is always in the last position in this list.") -(defvar tempo-collection nil +(defvar-local tempo-collection nil "A collection of all the tags defined for the current buffer.") -(defvar tempo-dirty-collection t +(defvar-local tempo-dirty-collection t "Indicates if the tag collection needs to be rebuilt.") -(defvar tempo-marks nil +(defvar-local tempo-marks nil "A list of marks to jump to with `\\[tempo-forward-mark]' and `\\[tempo-backward-mark]'.") -(defvar tempo-match-finder "\\b\\([[:word:]]+\\)\\=" +(defvar-local tempo-match-finder "\\b\\([[:word:]]+\\)\\=" "The regexp or function used to find the string to match against tags. If `tempo-match-finder' is a string, it should contain a regular @@ -195,23 +195,15 @@ A list of symbols which are bound to functions that take one argument. This function should return something to be sent to `tempo-insert' if it recognizes the argument, and nil otherwise.") -(defvar tempo-named-insertions nil +(defvar-local tempo-named-insertions nil "Temporary storage for named insertions.") -(defvar tempo-region-start (make-marker) +(defvar-local tempo-region-start (make-marker) "Region start when inserting around the region.") -(defvar tempo-region-stop (make-marker) +(defvar-local tempo-region-stop (make-marker) "Region stop when inserting around the region.") -;; Make some variables local to every buffer - -(make-variable-buffer-local 'tempo-marks) -(make-variable-buffer-local 'tempo-local-tags) -(make-variable-buffer-local 'tempo-match-finder) -(make-variable-buffer-local 'tempo-collection) -(make-variable-buffer-local 'tempo-dirty-collection) - ;;; Functions ;; @@ -268,11 +260,14 @@ The elements in ELEMENTS can be of several types: - `n>': Inserts a newline and indents line. - `o': Like `%' but leaves the point before the newline. - nil: It is ignored. - - Anything else: It is evaluated and the result is treated as an - element to be inserted. One additional tag is useful for these - cases. If an expression returns a list (l foo bar), the elements - after `l' will be inserted according to the usual rules. This makes - it possible to return several elements from one expression." + - Anything else: Each function in `tempo-user-elements' is called + with it as argument until one of them returns non-nil, and the + result is inserted. If all of them return nil, it is evaluated and + the result is treated as an element to be inserted. One additional + tag is useful for these cases. If an expression returns a list (l + foo bar), the elements after `l' will be inserted according to the + usual rules. This makes it possible to return several elements + from one expression." (let* ((template-name (intern (concat "tempo-template-" name))) (command-name template-name)) diff --git a/test/lisp/tempo-tests.el b/test/lisp/tempo-tests.el new file mode 100644 index 0000000000..6e610ffa6e --- /dev/null +++ b/test/lisp/tempo-tests.el @@ -0,0 +1,228 @@ +;;; tempo-tests.el --- Test suite for tempo.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; Author: Federico Tedin +;; Keywords: abbrev + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see . + +;;; Code: + +(require 'tempo) +(eval-when-compile (require 'cl-lib)) + +(ert-deftest tempo-string-element-test () + "Test a template containing a string element." + (with-temp-buffer + (tempo-define-template "test" '("GNU Emacs Tempo test")) + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "GNU Emacs Tempo test")))) + +(ert-deftest tempo-p-bare-element-test () + "Test a template containing a bare `p' element." + (with-temp-buffer + (tempo-define-template "test" '("abcde" p)) + (tempo-insert-template 'tempo-template-test nil) + (tempo-forward-mark) + (should (equal (point) 6)))) + +(ert-deftest tempo-r-bare-element-test () + "Test a template containing a bare `r' element." + (with-temp-buffer + (tempo-define-template "test" '("abcde" r "ghijk")) + (insert "F") + (set-mark (point)) + (goto-char (point-min)) + (tempo-insert-template 'tempo-template-test t) + (should (equal (buffer-string) "abcdeFghijk")))) + +(ert-deftest tempo-p-element-test () + "Testing template containing a `p' (prompt) element." + (with-temp-buffer + (tempo-define-template "test" '("hello " (p ">"))) + (let ((tempo-interactive t)) + (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "world"))) + (tempo-insert-template 'tempo-template-test nil)) + (should (equal (buffer-string) "hello world"))))) + +(ert-deftest tempo-P-element-test () + "Testing template containing a `P' (prompt) element." + (with-temp-buffer + (tempo-define-template "test" '("hello " (P ">"))) + ;; By default, `tempo-interactive' is nil, `P' should ignore this. + (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "world"))) + (tempo-insert-template 'tempo-template-test nil)) + (should (equal (buffer-string) "hello world")))) + +(ert-deftest tempo-r-element-test () + "Testing template containing an `r' (with prompt) element." + (with-temp-buffer + (tempo-define-template "test" '("abcde" (r ">") "ghijk")) + (let ((tempo-interactive t)) + (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "F"))) + (tempo-insert-template 'tempo-template-test nil)) + (should (equal (buffer-string) "abcdeFghijk"))))) + +(ert-deftest tempo-s-element-test () + "Testing template containing an `s' element." + (with-temp-buffer + (tempo-define-template "test" '("hello " (p ">" P1) " " (s P1))) + (let ((tempo-interactive t)) + (cl-letf (((symbol-function 'read-string) (lambda (&rest _) "world!"))) + (tempo-insert-template 'tempo-template-test nil)) + (should (equal (buffer-string) "hello world! world!"))))) + +(ert-deftest tempo-&-element-test () + "Testing template containing an `&' element." + (tempo-define-template "test" '(& "test")) + (with-temp-buffer + (insert " ") + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) " test"))) + (with-temp-buffer + (insert "hello") + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "hello\ntest")))) + +(ert-deftest tempo-%-element-test () + "Testing template containing an `%' element." + (tempo-define-template "test" '("test" %)) + (with-temp-buffer + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "test"))) + (with-temp-buffer + (insert "hello") + (goto-char (point-min)) + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "test\nhello")))) + +(ert-deftest tempo-n-element-test () + "Testing template containing an `n' element." + (tempo-define-template "test" '("test" n "test")) + (with-temp-buffer + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "test\ntest")))) + +(ert-deftest tempo-n>-element-test () + "Testing template containing an `n>' element." + (tempo-define-template "test" '("(progn" n> "(list 1 2 3))")) + (with-temp-buffer + (emacs-lisp-mode) + (tempo-insert-template 'tempo-template-test nil) + ;; Tempo should have inserted two spaces before (list 1 2 3) + (should (equal (buffer-string) "(progn\n (list 1 2 3))")))) + +(ert-deftest tempo->-element-test () + "Testing template containing a `>' element." + (with-temp-buffer + (emacs-lisp-mode) + (insert "(progn\n)") + (backward-char) + (tempo-define-template "test" '("(list 1 2 3)" >)) + (tempo-insert-template 'tempo-template-test nil) + ;; Tempo should have inserted two spaces before (list 1 2 3) + (should (equal (buffer-string) "(progn\n (list 1 2 3))")))) + +(ert-deftest tempo-r>-bare-element-test () + "Testing template containing a bare `r>' element." + (with-temp-buffer + (tempo-define-template "test" '("(progn" n r> ")")) + (emacs-lisp-mode) + (insert "(list 1 2 3)") + (set-mark (point)) + (goto-char (point-min)) + (tempo-insert-template 'tempo-template-test t) + ;; Tempo should have inserted two spaces before (list 1 2 3) + (should (equal (buffer-string) "(progn\n (list 1 2 3))")))) + +(ert-deftest tempo-r>-element-test () + "Testing template containing an `r>' (with prompt) element." + (tempo-define-template "test" '("(progn" n (r> ":") ")")) + (with-temp-buffer + ;; Test on-region use + (emacs-lisp-mode) + (insert "(list 1 2 3)") + (set-mark (point)) + (goto-char (point-min)) + (tempo-insert-template 'tempo-template-test t) + (should (equal (buffer-string) "(progn\n (list 1 2 3))"))) + (with-temp-buffer + ;; Test interactive use + (emacs-lisp-mode) + (let ((tempo-interactive t)) + (cl-letf (((symbol-function 'read-string) (lambda (&rest _) " (list 1 2 3)"))) + (tempo-insert-template 'tempo-template-test nil)) + (should (equal (buffer-string) "(progn\n (list 1 2 3))"))))) + +(ert-deftest tempo-o-element-test () + "Testing template containing an `o' element." + (with-temp-buffer + (tempo-define-template "test" '("test" o)) + (insert "hello") + (goto-char (point-min)) + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "test\nhello")) + (should (equal (point) 5)))) + +(ert-deftest tempo-nil-element-test () + "Testing template with nil elements." + (with-temp-buffer + (tempo-define-template "test" '("Hello," nil " World!")) + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "Hello, World!")))) + +(ert-deftest tempo-eval-element-test () + "Testing template with Emacs Lisp expressions." + (with-temp-buffer + (tempo-define-template "test" '((int-to-string (+ 1 1)) "=" (concat "1" "+1"))) + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "2=1+1")))) + +(ert-deftest tempo-l-element-test () + "Testing template containing an `l' element." + (with-temp-buffer + (tempo-define-template "test" '("list: " (l "1, " "2, " (int-to-string (+ 1 2))))) + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "list: 1, 2, 3")))) + +(ert-deftest tempo-tempo-user-elements-test () + "Testing a template with elements for `tempo-user-elements'." + (with-temp-buffer + (make-local-variable 'tempo-user-elements) + (add-to-list 'tempo-user-elements (lambda (x) (int-to-string (* x x)))) + (tempo-define-template "test" '(1 " " 2 " " 3 " " 4)) + (tempo-insert-template 'tempo-template-test nil) + (should (equal (buffer-string) "1 4 9 16")))) + +(ert-deftest tempo-expand-tag-test () + "Testing expansion of a template with a tag." + (with-temp-buffer + (tempo-define-template "test" '("Hello, World!") "hello") + (insert "hello") + (tempo-complete-tag) + (should (equal (buffer-string) "Hello, World!")))) + +(ert-deftest tempo-expand-partial-tag-test () + "Testing expansion of a template with a tag, with a partial match." + (with-temp-buffer + (tempo-define-template "test" '("Hello, World!") "hello") + (insert "hel") + (tempo-complete-tag) + (should (equal (buffer-string) "Hello, World!")))) + +(provide 'tempo-tests) +;;; tempo-tests.el ends here commit 5856512911488e40609be5685e64f9fb8cd395ad Author: Alan Mackenzie Date: Tue May 21 11:47:14 2019 +0000 C Mode: Fix indentation of DEFUN's function's argument list. Formally, when DEFUNs still used knr argument lists, these were indented by the syntactic context knr-argdecl-intro (5 columns). Since this is no longer the case, we now just use c-basic-offset (2 columns in "gnu" style). * lisp/progmodes/cc-align.el (c-indent-gnu-DEFUN-intro-cont): Modernize the indentation. Amend the doc string accordingly. diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el index 009f58ea58..74548f643a 100644 --- a/lisp/progmodes/cc-align.el +++ b/lisp/progmodes/cc-align.el @@ -90,26 +90,26 @@ Works with: topmost-intro-cont." (defun c-lineup-gnu-DEFUN-intro-cont (langelem) "Line up the continuation lines of a DEFUN macro in the Emacs C source. -These lines are indented as though they were `knr-argdecl-intro' lines. +These lines are indented `c-basic-offset' columns, usually from column 0. Return nil when we're not in such a construct. -This function is for historical compatibility with how previous CC Modes (5.28 -and earlier) indented such lines. +This function was formally for use in DEFUNs, which used to have knr +argument lists. Now (2019-05) it just indents the argument list of the +DEFUN's function, which would otherwise go to column 0. Here is an example: DEFUN (\"forward-char\", Fforward_char, Sforward_char, 0, 1, \"p\", doc: /* Move point right N characters (left if N is negative). On reaching end of buffer, stop and signal error. */) - (n) <- c-lineup-gnu-DEFUN-into-cont - Lisp_Object n; <- c-lineup-gnu-DEFUN-into-cont + (Lisp_Object n) <- c-lineup-gnu-DEFUN-into-cont Works with: topmost-intro-cont." (save-excursion (let (case-fold-search) (goto-char (c-langelem-pos langelem)) (if (looking-at "\\") - (c-calc-offset '(knr-argdecl-intro)))))) + c-basic-offset)))) (defun c-block-in-arglist-dwim (arglist-start) ;; This function implements the DWIM to avoid far indentation of