[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/android 0a113a32c43: Merge remote-tracking branch 'origin/master
From: |
Po Lu |
Subject: |
feature/android 0a113a32c43: Merge remote-tracking branch 'origin/master' into feature/android |
Date: |
Sat, 22 Apr 2023 20:37:10 -0400 (EDT) |
branch: feature/android
commit 0a113a32c43de3690365161b649f1afd9fd68da9
Merge: 74fd40c030b 3badd2358d5
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Merge remote-tracking branch 'origin/master' into feature/android
---
.dir-locals.el | 3 +
doc/lispintro/emacs-lisp-intro.texi | 9 +--
etc/NEWS | 18 ++++++
lisp/emacs-lisp/byte-opt.el | 47 +++++++++++----
lisp/progmodes/c-ts-mode.el | 5 ++
lisp/progmodes/python.el | 82 ++++++++++++++++++++++---
test/lisp/progmodes/python-tests.el | 116 +++++++++++++++++++++++++++++++++++-
7 files changed, 256 insertions(+), 24 deletions(-)
diff --git a/.dir-locals.el b/.dir-locals.el
index d8eece92245..f0f12db6717 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -21,6 +21,9 @@
(electric-quote-comment . nil)
(electric-quote-string . nil)
(mode . bug-reference-prog)))
+ (c-ts-mode . ((c-ts-mode-indent-style . gnu)
+ (indent-tabs-mode . t)
+ (mode . bug-reference-prog)))
(log-edit-mode . ((log-edit-font-lock-gnu-style . t)
(log-edit-setup-add-author . t)
(vc-git-log-edit-summary-target-len . 50)))
diff --git a/doc/lispintro/emacs-lisp-intro.texi
b/doc/lispintro/emacs-lisp-intro.texi
index a2b82d25633..6447ff74bc9 100644
--- a/doc/lispintro/emacs-lisp-intro.texi
+++ b/doc/lispintro/emacs-lisp-intro.texi
@@ -6604,10 +6604,11 @@ works. You will probably need to use @kbd{C-h f}
(@code{describe-function}). The newer version uses a conditional to
determine whether the buffer has been narrowed.
-(Also, it uses @code{line-number-at-pos}, which among other simple
-expressions, such as @code{(goto-char (point-min))}, moves point to
-the beginning of the current line with @code{(forward-line 0)} rather
-than @code{beginning-of-line}.)
+Also, the modern version of @code{what-line} uses
+@code{line-number-at-pos}, which among other simple expressions, such
+as @code{(goto-char (point-min))}, moves point to the beginning of the
+current line with @code{(forward-line 0)} rather than
+@code{beginning-of-line}.)
The @code{what-line} function as shown here has a documentation line
and is interactive, as you would expect. The next two lines use the
diff --git a/etc/NEWS b/etc/NEWS
index 114b41374cd..79e45536fb5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -298,6 +298,24 @@ distracting and easily confused with actual code, or a
significant
early aid that relieves you from moving the buffer or reaching for the
mouse to consult an error message.
+** Python mode
+
+---
+*** New user option 'python-indent-block-paren-deeper'.
+If non-nil, increase the indentation of the lines inside parens in a
+header of a block when they are indented to the same level as the body
+of the block:
+
+ if (some_expression
+ and another_expression):
+ do_something()
+
+instead of:
+
+ if (some_expression
+ and another_expression):
+ do_something()
+
* New Modes and Packages in Emacs 30.1
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 2bdd3375728..da997212eef 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -1520,6 +1520,35 @@ See Info node `(elisp) Integer Basics'."
;; (list) -> nil
(and (cdr form) form))
+(put 'nconc 'byte-optimizer #'byte-optimize-nconc)
+(defun byte-optimize-nconc (form)
+ (pcase (cdr form)
+ ('nil nil) ; (nconc) -> nil
+ (`(,x) x) ; (nconc X) -> X
+ (_ (named-let loop ((args (cdr form)) (newargs nil))
+ (if args
+ (let ((arg (car args))
+ (prev (car newargs)))
+ (cond
+ ;; Elide null args.
+ ((null arg) (loop (cdr args) newargs))
+ ;; Merge consecutive `list' args.
+ ((and (eq (car-safe arg) 'list)
+ (eq (car-safe prev) 'list))
+ (loop (cons (cons (car prev) (append (cdr prev) (cdr arg)))
+ (cdr args))
+ (cdr newargs)))
+ ;; (nconc ... (list A) B ...) -> (nconc ... (cons A B) ...)
+ ((and (eq (car-safe prev) 'list) (cdr prev) (null (cddr prev)))
+ (loop (cdr args)
+ (cons (list 'cons (cadr prev) arg)
+ (cdr newargs))))
+ (t (loop (cdr args) (cons arg newargs)))))
+ (let ((new-form (cons (car form) (nreverse newargs))))
+ (if (equal new-form form)
+ form
+ new-form)))))))
+
(put 'append 'byte-optimizer #'byte-optimize-append)
(defun byte-optimize-append (form)
;; There is (probably) too much code relying on `append' to return a
@@ -1572,11 +1601,9 @@ See Info node `(elisp) Integer Basics'."
;; (append X) -> X
((null newargs) arg)
- ;; (append (list Xs...) nil) -> (list Xs...)
- ((and (null arg)
- newargs (null (cdr newargs))
- (consp prev) (eq (car prev) 'list))
- prev)
+ ;; (append ... (list Xs...) nil) -> (append ... (list Xs...))
+ ((and (null arg) (eq (car-safe prev) 'list))
+ (cons (car form) (nreverse newargs)))
;; (append '(X) Y) -> (cons 'X Y)
;; (append (list X) Y) -> (cons X Y)
@@ -1587,13 +1614,13 @@ See Info node `(elisp) Integer Basics'."
(= (length (cadr prev)) 1)))
((eq (car prev) 'list)
(= (length (cdr prev)) 1))))
- (list 'cons (if (eq (car prev) 'quote)
- (macroexp-quote (caadr prev))
- (cadr prev))
- arg))
+ `(cons ,(if (eq (car prev) 'quote)
+ (macroexp-quote (caadr prev))
+ (cadr prev))
+ ,arg))
(t
- (let ((new-form (cons 'append (nreverse (cons arg newargs)))))
+ (let ((new-form (cons (car form) (nreverse (cons arg newargs)))))
(if (equal new-form form)
form
new-form))))))))
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 2309aa00fc9..bbc7979667c 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -136,6 +136,10 @@ symbol."
(loop (append res (list buffer)) (cdr buffers))
(loop res (cdr buffers))))))))
+(defun c-ts-indent-style-safep (style)
+ "Non-nil if STYLE's value is safe for file-local variables."
+ (and (symbolp style) (not (functionp style))))
+
(defcustom c-ts-mode-indent-style 'gnu
"Style used for indentation.
@@ -150,6 +154,7 @@ follows the form of `treesit-simple-indent-rules'."
(symbol :tag "BSD" bsd)
(function :tag "A function for user customized style" ignore))
:set #'c-ts-mode--indent-style-setter
+ :safe 'c-ts-indent-style-safep
:group 'c)
(defun c-ts-mode--get-indent-style (mode)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index bbabce80b4d..5bb15c60956 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1265,11 +1265,59 @@ For NODE, OVERRIDE, START, END, and ARGS, see
:type '(repeat symbol))
(defcustom python-indent-def-block-scale 2
- "Multiplier applied to indentation inside multi-line def blocks."
+ "Multiplier applied to indentation inside multi-line blocks.
+The indentation in parens in the block header will be the current
+indentation plus `python-indent-offset' multiplied by this
+variable. For example, the arguments are indented as follows if
+this variable is 1:
+
+ def do_something(
+ arg1,
+ arg2):
+ print('hello')
+
+if this variable is 2 (default):
+
+ def do_something(
+ arg1,
+ arg2):
+ print('hello')
+
+This variable has an effect on all blocks, not just def block.
+This variable only works if the opening paren is not followed by
+non-whitespace characters on the same line. Modify
+`python-indent-block-paren-deeper' to customize the case where
+non-whitespace characters follow the opening paren on the same
+line."
:version "26.1"
:type 'integer
:safe 'natnump)
+(defcustom python-indent-block-paren-deeper nil
+ "Increase indentation inside parens of a block.
+If non-nil, increase the indentation of the lines inside parens
+in a header of a block when they are indented to the same level
+as the body of the block:
+
+ if (some_expression
+ and another_expression):
+ do_something()
+
+instead of:
+
+ if (some_expression
+ and another_expression):
+ do_something()
+
+This variable only works if the opening paren is followed by
+non-whitespace characters on the same line. Modify
+`python-indent-def-block-scale' to customize the case where
+non-whitespace character does not follow the opening paren on the
+same line."
+ :version "30.1"
+ :type 'boolean
+ :safe 'booleanp)
+
(defvar python-indent-current-level 0
"Deprecated var available for compatibility.")
@@ -1367,6 +1415,10 @@ keyword
- Point is inside a paren with items starting in their own line
from a block start.
- START is the position of the open paren.
+:inside-paren-from-block
+ - Point is inside a paren from a block start followed by some
+ items on the same line.
+ - START is the first non space char position *after* the open paren.
:after-backslash
- Fallback case when point is after backslash.
@@ -1450,12 +1502,16 @@ keyword
(starts-in-newline
(cons :inside-paren-newline-start start))
;; General case.
- (t (cons :inside-paren
- (save-excursion
- (goto-char (1+ start))
- (skip-syntax-forward "(" 1)
- (skip-syntax-forward " ")
- (point))))))))
+ (t (let ((after-start (save-excursion
+ (goto-char (1+ start))
+ (skip-syntax-forward "(" 1)
+ (skip-syntax-forward " ")
+ (point))))
+ (if (save-excursion
+ (python-nav-beginning-of-statement)
+ (python-info-looking-at-beginning-of-block))
+ (cons :inside-paren-from-block after-start)
+ (cons :inside-paren after-start))))))))
;; After backslash.
((let ((start (when (not (python-syntax-comment-or-string-p ppss))
(python-info-line-ends-backslash-p
@@ -1603,7 +1659,17 @@ possibilities can be narrowed to specific indentation
points."
(`(,(or :inside-paren-newline-start-from-block) . ,start)
(goto-char start)
(+ (current-indentation)
- (* python-indent-offset python-indent-def-block-scale))))))
+ (* python-indent-offset python-indent-def-block-scale)))
+ (`(,:inside-paren-from-block . ,start)
+ (goto-char start)
+ (let ((column (current-column)))
+ (if (and python-indent-block-paren-deeper
+ (= column (+ (save-excursion
+ (python-nav-beginning-of-statement)
+ (current-indentation))
+ python-indent-offset)))
+ (+ column python-indent-offset)
+ column))))))
(defun python-indent--calculate-levels (indentation)
"Calculate levels list given INDENTATION.
diff --git a/test/lisp/progmodes/python-tests.el
b/test/lisp/progmodes/python-tests.el
index 50153e66da5..60b11d572cf 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -1139,7 +1139,7 @@ while ((not some_condition) and
(should (eq (car (python-indent-context)) :no-indent))
(should (= (python-indent-calculate-indentation) 0))
(forward-line 1)
- (should (eq (car (python-indent-context)) :inside-paren))
+ (should (eq (car (python-indent-context)) :inside-paren-from-block))
(should (= (python-indent-calculate-indentation) 7))
(forward-line 1)
(should (eq (car (python-indent-context)) :after-block-start))
@@ -1174,6 +1174,118 @@ CHOICES = (('some', 'choice'),
;; This signals an error if the test fails
(should (eq (car (python-indent-context)) :inside-paren-newline-start))))
+(ert-deftest python-indent-inside-paren-block-1 ()
+ "`python-indent-block-paren-deeper' set to nil (default).
+See Bug#62696."
+ (python-tests-with-temp-buffer
+ "
+if ('VALUE' in my_unnecessarily_long_dictionary and
+ some_other_long_condition_case):
+ do_something()
+elif (some_case or
+ another_case):
+ do_another()
+"
+ (python-tests-look-at "if")
+ (should (eq (car (python-indent-context)) :no-indent))
+ (should (= (python-indent-calculate-indentation) 0))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :inside-paren-from-block))
+ (should (= (python-indent-calculate-indentation) 4))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :after-block-start))
+ (should (= (python-indent-calculate-indentation) 4))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :at-dedenter-block-start))
+ (should (= (python-indent-calculate-indentation) 0))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :inside-paren-from-block))
+ (should (= (python-indent-calculate-indentation) 6))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :after-block-start))
+ (should (= (python-indent-calculate-indentation) 4))))
+
+(ert-deftest python-indent-inside-paren-block-2 ()
+ "`python-indent-block-paren-deeper' set to t.
+See Bug#62696."
+ (python-tests-with-temp-buffer
+ "
+if ('VALUE' in my_unnecessarily_long_dictionary and
+ some_other_long_condition_case):
+ do_something()
+elif (some_case or
+ another_case):
+ do_another()
+"
+ (let ((python-indent-block-paren-deeper t))
+ (python-tests-look-at "if")
+ (should (eq (car (python-indent-context)) :no-indent))
+ (should (= (python-indent-calculate-indentation) 0))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :inside-paren-from-block))
+ (should (= (python-indent-calculate-indentation) 8))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :after-block-start))
+ (should (= (python-indent-calculate-indentation) 4))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :at-dedenter-block-start))
+ (should (= (python-indent-calculate-indentation) 0))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :inside-paren-from-block))
+ (should (= (python-indent-calculate-indentation) 6))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :after-block-start))
+ (should (= (python-indent-calculate-indentation) 4)))))
+
+(ert-deftest python-indent-inside-paren-block-3 ()
+ "With backslash. `python-indent-block-paren-deeper' set to nil (default).
+See Bug#62696."
+ (python-tests-with-temp-buffer
+ "
+if 'VALUE' in my_uncessarily_long_dictionary and\\
+ (some_other_long_condition_case or
+ another_case):
+ do_something()
+"
+ (python-tests-look-at "if")
+ (should (eq (car (python-indent-context)) :no-indent))
+ (should (= (python-indent-calculate-indentation) 0))
+ (forward-line 1)
+ (should (eq (car (python-indent-context))
+ :after-backslash-block-continuation))
+ (should (= (python-indent-calculate-indentation) 3))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :inside-paren-from-block))
+ (should (= (python-indent-calculate-indentation) 4))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :after-block-start))
+ (should (= (python-indent-calculate-indentation) 4))))
+
+(ert-deftest python-indent-inside-paren-block-4 ()
+ "With backslash. `python-indent-block-paren-deeper' set to t.
+See Bug#62696."
+ (python-tests-with-temp-buffer
+ "
+if 'VALUE' in my_uncessarily_long_dictionary and\\
+ (some_other_long_condition_case or
+ another_case):
+ do_something()
+"
+ (let ((python-indent-block-paren-deeper t))
+ (python-tests-look-at "if")
+ (should (eq (car (python-indent-context)) :no-indent))
+ (should (= (python-indent-calculate-indentation) 0))
+ (forward-line 1)
+ (should (eq (car (python-indent-context))
+ :after-backslash-block-continuation))
+ (should (= (python-indent-calculate-indentation) 3))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :inside-paren-from-block))
+ (should (= (python-indent-calculate-indentation) 8))
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) :after-block-start))
+ (should (= (python-indent-calculate-indentation) 4)))))
+
(ert-deftest python-indent-after-block-1 ()
"The most simple after-block case that shouldn't fail."
(python-tests-with-temp-buffer
@@ -1670,7 +1782,7 @@ a == 4):
(should (= (python-indent-calculate-indentation) 0))
(should (= (python-indent-calculate-indentation t) 0))
(python-tests-look-at "a == 4):\n")
- (should (eq (car (python-indent-context)) :inside-paren))
+ (should (eq (car (python-indent-context)) :inside-paren-from-block))
(should (= (python-indent-calculate-indentation) 6))
(python-indent-line)
(should (= (python-indent-calculate-indentation t) 4))