commit 79510d81d87488062c41a27279aaf0815c7933bc (HEAD, refs/remotes/origin/master) Author: Stefan Kangas Date: Tue Jan 9 07:55:51 2024 +0100 Use `min`/`max` macros in a few more places * src/bidi.c (bidi_set_sos_type): * src/coding.c (consume_chars): * src/dosfns.c (dos_memory_info): * src/emacs.c (sort_args): * src/insdel.c (count_combining_before) (count_combining_after, replace_range, del_range_2): * src/sort.c (tim_sort): * src/w32.c (sys_write): * src/xfaces.c (face_at_buffer_position) (face_for_overlay_string): Prefer using 'min' and 'max' macros. diff --git a/src/bidi.c b/src/bidi.c index 93bb061ac32..a2b5054cb60 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -420,7 +420,7 @@ bidi_paired_bracket_type (int c) static void bidi_set_sos_type (struct bidi_it *bidi_it, int level_before, int level_after) { - int higher_level = (level_before > level_after ? level_before : level_after); + int higher_level = max (level_before, level_after); /* FIXME: should the default sos direction be user selectable? */ bidi_it->sos = ((higher_level & 1) != 0 ? R2L : L2R); /* X10 */ diff --git a/src/coding.c b/src/coding.c index 219e3554c18..a5bec8b6305 100644 --- a/src/coding.c +++ b/src/coding.c @@ -7658,8 +7658,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table, if (pos == stop_charset) buf = handle_charset_annotation (pos, end_pos, coding, buf, &stop_charset); - stop = (stop_composition < stop_charset - ? stop_composition : stop_charset); + stop = min (stop_composition, stop_charset); } if (! multibytep) diff --git a/src/dosfns.c b/src/dosfns.c index 3eb3b34145e..96087116c19 100644 --- a/src/dosfns.c +++ b/src/dosfns.c @@ -652,10 +652,7 @@ dos_memory_info (unsigned long *totalram, unsigned long *freeram, mem2 *= 4096; /* Surely, the available memory is at least what we have physically available, right? */ - if (mem1 >= mem2) - freemem = mem1; - else - freemem = mem2; + freemem = max (mem1, mem2); *freeram = freemem; *totalswap = ((long)info.max_pages_in_paging_file == -1L) diff --git a/src/emacs.c b/src/emacs.c index eb1871841ec..97c65fbfd33 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -2900,7 +2900,7 @@ sort_args (int argc, char **argv) new[to++] = argv[best + i + 1]; } - incoming_used += 1 + (options[best] > 0 ? options[best] : 0); + incoming_used += 1 + max (options[best], 0); /* Clear out this option in ARGV. */ argv[best] = 0; diff --git a/src/insdel.c b/src/insdel.c index e41d9945551..3809f8bc060 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -803,7 +803,7 @@ count_combining_before (const unsigned char *string, ptrdiff_t length, while (!CHAR_HEAD_P (*p) && p < string + length) p++; - return (combining_bytes < p - string ? combining_bytes : p - string); + return min (combining_bytes, p - string); } /* See if the bytes after POS/POS_BYTE combine with bytes @@ -865,7 +865,7 @@ count_combining_after (const unsigned char *string, bufp++, pos_byte++; while (!CHAR_HEAD_P (*bufp)) bufp++, pos_byte++; - return (bytes <= pos_byte - opos_byte ? bytes : pos_byte - opos_byte); + return min (bytes, pos_byte - opos_byte); } #endif @@ -1568,9 +1568,8 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, /* Relocate point as if it were a marker. */ if (from < PT) - adjust_point ((from + inschars - (PT < to ? PT : to)), - (from_byte + outgoing_insbytes - - (PT_BYTE < to_byte ? PT_BYTE : to_byte))); + adjust_point ((from + inschars - min (PT, to)), + (from_byte + outgoing_insbytes - min (PT_BYTE, to_byte))); check_markers (); @@ -1919,8 +1918,8 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte, /* Relocate point as if it were a marker. */ if (from < PT) - adjust_point (from - (PT < to ? PT : to), - from_byte - (PT_BYTE < to_byte ? PT_BYTE : to_byte)); + adjust_point (from - min (PT, to), + from_byte - min (PT_BYTE, to_byte)); offset_intervals (current_buffer, from, - nchars_del); diff --git a/src/sort.c b/src/sort.c index 5f7a1ee2f53..2f98bfa648c 100644 --- a/src/sort.c +++ b/src/sort.c @@ -946,8 +946,7 @@ tim_sort (Lisp_Object predicate, Lisp_Object *seq, const ptrdiff_t length) /* If the run is short, extend it to min(minrun, nremaining). */ if (n < minrun) { - const ptrdiff_t force = nremaining <= minrun ? - nremaining : minrun; + const ptrdiff_t force = min (nremaining, minrun); binarysort (&ms, lo, lo + force, lo + n); n = force; } diff --git a/src/w32.c b/src/w32.c index f365616db2b..df5465c2135 100644 --- a/src/w32.c +++ b/src/w32.c @@ -9414,7 +9414,7 @@ sys_write (int fd, const void * buffer, unsigned int count) errno = 0; while (count > 0) { - unsigned this_chunk = count < chunk ? count : chunk; + unsigned this_chunk = min (count, chunk); int n = _write (fd, p, this_chunk); if (n > 0) diff --git a/src/xfaces.c b/src/xfaces.c index e30c2fac70c..c9ade2769bd 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -6646,7 +6646,7 @@ face_at_buffer_position (struct window *w, ptrdiff_t pos, /* Get the `face' or `mouse_face' text property at POS, and determine the next position at which the property changes. */ prop = Fget_text_property (position, propname, w->contents); - XSETFASTINT (limit1, (limit < endpos ? limit : endpos)); + XSETFASTINT (limit1, min (limit, endpos)); end = Fnext_single_property_change (position, propname, w->contents, limit1); if (FIXNUMP (end)) endpos = XFIXNUM (end); @@ -6782,7 +6782,7 @@ face_for_overlay_string (struct window *w, ptrdiff_t pos, /* Get the `face' or `mouse_face' text property at POS, and determine the next position at which the property changes. */ prop = Fget_text_property (position, propname, w->contents); - XSETFASTINT (limit1, (limit < endpos ? limit : endpos)); + XSETFASTINT (limit1, min (limit, endpos)); end = Fnext_single_property_change (position, propname, w->contents, limit1); if (FIXNUMP (end)) endpos = XFIXNUM (end); commit 774c8ec74c98d69d56b2511a613145f2b69fb2eb Author: Harald Jörg Date: Mon Jan 8 16:12:19 2024 +0100 cperl-mode.el: Make sure cperl-file-style is set buffer-local * lisp/progmodes/cperl-mode.el (cperl-file-style): Add description what the options actually do. (cperl-menu): Split the menu entry "Indent styles" into "Default indent styles" and "Indent styles for current buffer" (cperl--set-file-style): call `cperl-file-style' instead of `cperl-set-style'. This completes the fix for Bug#17948. (cperl-set-style): Explain when to use `cperl-file-style'. Use `set-default-toplevel-value' instead of `set'. (cperl-set-style-back): Use `set-default-toplevel-value' instead of `set'. (cperl-file-style): New command to set the file style for the current buffer. * etc/NEWS: Announce the new command cperl-file-style. diff --git a/etc/NEWS b/etc/NEWS index c3d777b971f..f4d008ee2d6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1116,6 +1116,11 @@ value of 'perl-code' is useful for trailing POD and for AutoSplit modules, the value 'comment' makes CPerl mode treat trailers as comment, like Perl mode does. +*** New command 'cperl-file-style'. +This command sets the indentation style for the current buffer. To +change the default style, either use the option with the same name or +use the command cperl-set-style. + *** Commands using the Perl info page are obsolete. The Perl documentation in info format is no longer distributed with Perl or on CPAN since more than 10 years. Perl documentation can be diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 9f7f29b8182..5e435f7133e 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el @@ -162,6 +162,9 @@ for constructs with multiline if/unless/while/until/for/foreach condition." (defcustom cperl-file-style nil "Indentation style to use in cperl-mode. +Setting this option will override options as given in +`cperl-style-alist' for the keyword provided here. If nil, then +the individual options as customized are used. \"PBP\" is the style recommended in the Book \"Perl Best Practices\" by Damian Conway. \"CPerl\" is the traditional style of cperl-mode, and \"PerlStyle\" follows the Perl documentation @@ -1130,7 +1133,7 @@ Unless KEEP, removes the old indentation." ["Fix whitespace on indent" cperl-toggle-construct-fix t] ["Auto-help on Perl constructs" cperl-toggle-autohelp t] ["Auto fill" auto-fill-mode t]) - ("Indent styles..." + ("Default indent styles..." ["CPerl" (cperl-set-style "CPerl") t] ["PBP" (cperl-set-style "PBP") t] ["PerlStyle" (cperl-set-style "PerlStyle") t] @@ -1141,6 +1144,15 @@ Unless KEEP, removes the old indentation." ["Whitesmith" (cperl-set-style "Whitesmith") t] ["Memorize Current" (cperl-set-style "Current") t] ["Memorized" (cperl-set-style-back) cperl-old-style]) + ("Indent styles for current buffer..." + ["CPerl" (cperl-set-style "CPerl") t] + ["PBP" (cperl-file-style "PBP") t] + ["PerlStyle" (cperl-file-style "PerlStyle") t] + ["GNU" (cperl-file-style "GNU") t] + ["C++" (cperl-file-style "C++") t] + ["K&R" (cperl-file-style "K&R") t] + ["BSD" (cperl-file-style "BSD") t] + ["Whitesmith" (cperl-file-style "Whitesmith") t]) ("Micro-docs" ["Tips" (describe-variable 'cperl-tips) t] ["Problems" (describe-variable 'cperl-problems) t] @@ -1924,7 +1936,8 @@ or as help on variables `cperl-tips', `cperl-problems', (defun cperl--set-file-style () (when cperl-file-style - (cperl-set-style cperl-file-style))) + (cperl-file-style cperl-file-style))) + ;; Fix for perldb - make default reasonable (defun cperl-db () @@ -6496,6 +6509,10 @@ See examples in `cperl-style-examples'.") (defun cperl-set-style (style) "Set CPerl mode variables to use one of several different indentation styles. +This command sets the default values for the variables. It does +not affect buffers visiting files where the style has been set as +a file or directory variable. To change the indentation style of +a buffer, use the command `cperl-file-style' instead. The arguments are a string representing the desired style. The list of styles is in `cperl-style-alist', available styles are \"CPerl\", \"PBP\", \"PerlStyle\", \"GNU\", \"K&R\", \"BSD\", \"C++\" @@ -6516,7 +6533,8 @@ side-effect of memorizing only. Examples in `cperl-style-examples'." (let ((style (cdr (assoc style cperl-style-alist))) setting) (while style (setq setting (car style) style (cdr style)) - (set (car setting) (cdr setting))))) + (set-default-toplevel-value (car setting) (cdr setting)))) + (set-default-toplevel-value 'cperl-file-style style)) (defun cperl-set-style-back () "Restore a style memorized by `cperl-set-style'." @@ -6526,7 +6544,22 @@ side-effect of memorizing only. Examples in `cperl-style-examples'." (while cperl-old-style (setq setting (car cperl-old-style) cperl-old-style (cdr cperl-old-style)) - (set (car setting) (cdr setting))))) + (set-default-toplevel-value (car setting) (cdr setting))))) + +(defun cperl-file-style (style) + "Set the indentation style for the current buffer to STYLE. +The list of styles is in `cperl-style-alist', available styles +are \"CPerl\", \"PBP\", \"PerlStyle\", \"GNU\", \"K&R\", \"BSD\", \"C++\" +and \"Whitesmith\"." + (interactive + (list (completing-read "Enter style: " cperl-style-alist nil 'insist))) + (dolist (setting (cdr (assoc style cperl-style-alist)) style) + (let ((option (car setting)) + (value (cdr setting))) + (make-variable-buffer-local option) + (set option value))) + (make-variable-buffer-local 'cperl-file-style) + (setq cperl-file-style style)) (declare-function Info-find-node "info" (filename nodename &optional no-going-back strict-case commit d9462e24a967e32d550ee886b5150f0cc78358f6 Author: Michael Albinus Date: Mon Jan 8 14:52:25 2024 +0100 Make Tramp more robust * lisp/net/tramp-sh.el (tramp-bundle-read-file-names): Check, that the command finishes successfully. diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 6489f473634..8ec9467ab45 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -3652,20 +3652,20 @@ filled are described in `tramp-bundle-read-file-names'." (dolist (elt - (ignore-errors + (with-current-buffer (tramp-get-connection-buffer vec) ;; We cannot use `tramp-send-command-and-read', because ;; this does not cooperate well with heredoc documents. - (tramp-send-command - vec - (format - "tramp_bundle_read_file_names <<'%s'\n%s\n%s\n" - tramp-end-of-heredoc - (mapconcat #'tramp-shell-quote-argument files "\n") - tramp-end-of-heredoc)) - (with-current-buffer (tramp-get-connection-buffer vec) - ;; Read the expression. - (goto-char (point-min)) - (read (current-buffer))))) + (unless (tramp-send-command-and-check + vec + (format + "tramp_bundle_read_file_names <<'%s'\n%s\n%s\n" + tramp-end-of-heredoc + (mapconcat #'tramp-shell-quote-argument files "\n") + tramp-end-of-heredoc)) + (tramp-error vec 'file-error "%s" (tramp-get-buffer-string))) + ;; Read the expression. + (goto-char (point-min)) + (read (current-buffer)))) (tramp-set-file-property vec (car elt) "file-exists-p" (nth 1 elt)) (tramp-set-file-property vec (car elt) "file-readable-p" (nth 2 elt))