Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closure indentation #584

Closed
xendk opened this issue Nov 7, 2019 · 2 comments · Fixed by #585
Closed

Closure indentation #584

xendk opened this issue Nov 7, 2019 · 2 comments · Fixed by #585
Assignees

Comments

@xendk
Copy link

xendk commented Nov 7, 2019

Most coding styles doesn't like the way php-mode indents inline functions in function args much. An example:

image

I'd try fiddling with it myself, but I have had no luck c-add-styleing a new style and php-set-styleing it, and actually have it change anything about indentation, so I obviously don't understand how it works.

How would one go about trying to fix this?

@zonuexe
Copy link
Member

zonuexe commented Nov 11, 2019

@xendk
Can you provide it with text instead of image? Also please be sure to tell me the output of M-x php-mode-debug along with the bug report.

@xendk
Copy link
Author

xendk commented Nov 11, 2019

@zonuexe

Here's a cut down testcase:

<?php

imaginary_func(function ($x): void {

});

Pressing tab on the empty line produces

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p (23 44 43 44 #<buffer tmp>))
  goto-char((23 44 43 44 #<buffer tmp>))
  (progn (goto-char (match-data 1)) (not (php-in-string-or-comment-p)))
  (and (re-search-backward php-mode--re-return-typed-closure (cdr langelem) t) (progn (goto-char (match-data 1)) (not (php-in-string-or-comment-p))))
  (if (and (re-search-backward php-mode--re-return-typed-closure (cdr langelem) t) (progn (goto-char (match-data 1)) (not (php-in-string-or-comment-p)))) (progn (setq in-return-typed-closure t)))
  (progn (if (and (re-search-backward php-mode--re-return-typed-closure (cdr langelem) t) (progn (goto-char (match-data 1)) (not (php-in-string-or-comment-p)))) (progn (setq in-return-typed-closure t))))
  (unwind-protect (progn (if (and (re-search-backward php-mode--re-return-typed-closure (cdr langelem) t) (progn (goto-char (match-data 1)) (not (php-in-string-or-comment-p)))) (progn (setq in-return-typed-closure t)))) (set-match-data save-match-data-internal (quote evaporate)))
  (let ((save-match-data-internal (match-data))) (unwind-protect (progn (if (and (re-search-backward php-mode--re-return-typed-closure (cdr langelem) t) (progn (goto-char (match-data 1)) (not (php-in-string-or-comment-p)))) (progn (setq in-return-typed-closure t)))) (set-match-data save-match-data-internal (quote evaporate))))
  (save-excursion (let ((save-match-data-internal (match-data))) (unwind-protect (progn (if (and (re-search-backward php-mode--re-return-typed-closure (cdr langelem) t) (progn (goto-char ...) (not ...))) (progn (setq in-return-typed-closure t)))) (set-match-data save-match-data-internal (quote evaporate)))))
  (progn (save-excursion (let ((save-match-data-internal (match-data))) (unwind-protect (progn (if (and (re-search-backward php-mode--re-return-typed-closure ... t) (progn ... ...)) (progn (setq in-return-typed-closure t)))) (set-match-data save-match-data-internal (quote evaporate))))))
  (if (and (consp langelem) (eq (quote arglist-cont-nonempty) (car langelem))) (progn (save-excursion (let ((save-match-data-internal (match-data))) (unwind-protect (progn (if (and ... ...) (progn ...))) (set-match-data save-match-data-internal (quote evaporate)))))))
  (let (in-return-typed-closure) (if (and (consp langelem) (eq (quote arglist-cont-nonempty) (car langelem))) (progn (save-excursion (let ((save-match-data-internal (match-data))) (unwind-protect (progn (if ... ...)) (set-match-data save-match-data-internal (quote evaporate))))))) (if in-return-typed-closure nil (c-lineup-arglist langelem)))
  php-c-lineup-arglist((arglist-cont-nonempty . 8))
  c-evaluate-offset(php-c-lineup-arglist (arglist-cont-nonempty 8 22) arglist-cont-nonempty)
  c-evaluate-offset((first php-lineup-cascaded-calls php-c-lineup-arglist) (arglist-cont-nonempty 8 22) arglist-cont-nonempty)
  c-calc-offset((arglist-cont-nonempty 8 22))
  c-get-syntactic-indentation(((arglist-cont-nonempty 8 22) (defun-block-intro 8)))
  c-indent-line()
  funcall(c-indent-line)
  (progn (funcall (quote c-indent-line)))
  (if doit (progn (funcall (quote c-indent-line))))
  (let ((here (point)) doit) (move-beginning-of-line nil) (let ((save-match-data-internal (match-data))) (unwind-protect (progn (if (and (looking-at "[a-zA-Z0-9_]+;\n") (php-in-string-p)) nil (setq doit t))) (set-match-data save-match-data-internal (quote evaporate)))) (goto-char here) (if doit (progn (funcall (quote c-indent-line)))))
  (if (or (not php-mode-warn-if-mumamo-off) (not (php-in-poly-php-html-mode)) php-warned-bad-indent (php-check-html-for-indentation)) (let ((here (point)) doit) (move-beginning-of-line nil) (let ((save-match-data-internal (match-data))) (unwind-protect (progn (if (and (looking-at "[a-zA-Z0-9_]+;\n") (php-in-string-p)) nil (setq doit t))) (set-match-data save-match-data-internal (quote evaporate)))) (goto-char here) (if doit (progn (funcall (quote c-indent-line))))))
  php-cautious-indent-line()
  indent--funcall-widened(php-cautious-indent-line)
  indent-for-tab-command()
  (if (or (bolp) (region-active-p) (eq (char-syntax (char-before)) 32)) (indent-for-tab-command))
  xen-tab()
  funcall-interactively(xen-tab)
  call-interactively(xen-tab nil nil)
  command-execute(xen-tab)

In producing the test case I discovered that it seems to be the return type hint that throws it off.

`M-x php-mode-debug:

--- PHP-MODE DEBUG BEGIN ---
versions: GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.12)
 of 2019-10-27, modified by Debian; PHP Mode 1.22.1 of 2019-11-10
package-version: nil
major-mode: php-mode
minor-modes: (diff-auto-refine-mode magit-auto-revert-mode async-bytecomp-package-mode flycheck-color-mode-line-mode lsp-ui-sideline-mode yas-minor-mode doom-modeline-mode shell-dirtrack-mode auto-insert-mode flycheck-mode company-mode winner-mode undo-tree-mode show-smartparens-mode smartparens-mode save-place-mode projectile-mode keyfreq-autosave-mode keyfreq-mode ivy-mode delete-selection-mode editorconfig-mode straight-use-package-mode straight-package-neutering-mode tooltip-mode electric-indent-mode mouse-wheel-mode file-name-shadow-mode font-lock-mode blink-cursor-mode auto-composition-mode auto-encryption-mode auto-compression-mode line-number-mode transient-mark-mode abbrev-mode)
variables: ((indent-tabs-mode nil) (tab-width 8))
custom variables: ((php-extras-insert-previous-variable-key [(control c) (control $)]) (php-extras-auto-complete-insert-parenthesis nil) (php-executable /usr/bin/php) (php-site-url https://php.net/) (php-manual-url en) (php-search-url nil) (php-class-suffix-when-insert ::) (php-namespace-suffix-when-insert \) (php-default-major-mode php-mode) (php-html-template-major-mode web-mode) (php-blade-template-major-mode web-mode) (php-template-mode-alist ((\.blade . web-mode) (\.phpt\' . php-mode) (\.phtml\' . web-mode))) (php-mode-maybe-hook nil) (php-default-builtin-web-server-port 3939) (php-re-detect-html-tag php-re-detect-html-tag-default) (php-search-documentation-browser-function nil))
c-indentation-style: psr2
c-style-variables: ((c-basic-offset 4) (c-comment-only-line-offset 0) (c-indent-comment-alist ((anchored-comment column . 0) (end-block space . 1) (cpp-end-block space . 2))) (c-indent-comments-syntactically-p t) (c-block-comment-prefix * ) (c-comment-prefix-regexp ((pike-mode . //+!?\|\**) (awk-mode . #+) (other . //+\|\**))) (c-cleanup-list (scope-operator)) (c-hanging-braces-alist ((brace-list-open) (brace-entry-open) (statement-cont) (substatement-open after) (block-close . c-snug-do-while) (extern-lang-open after) (namespace-open after) (module-open after) (composition-open after) (inexpr-class-open after) (inexpr-class-close before) (arglist-cont-nonempty))) (c-hanging-colons-alist nil) (c-hanging-semi&comma-criteria (c-semi&comma-inside-parenlist)) (c-backslash-column 48) (c-backslash-max-column 72) (c-special-indent-hook nil) (c-label-minimum-indentation 1))
c-doc-comment-style: ((java-mode . javadoc) (pike-mode . autodoc) (c-mode . gtkdoc))
c-offsets-alist: ((inexpr-class . +) (inexpr-statement . +) (template-args-cont c-lineup-template-args +) (incomposition . +) (inmodule . +) (innamespace . +) (inextern-lang . +) (composition-close . 0) (module-close . 0) (namespace-close . 0) (extern-lang-close . 0) (composition-open . 0) (module-open . 0) (extern-lang-open . 0) (objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call +) (objc-method-args-cont . c-lineup-ObjC-method-args) (objc-method-intro . [0]) (friend . 0) (cpp-define-intro c-lineup-cpp-define +) (cpp-macro-cont . +) (cpp-macro . [0]) (inclass . +) (stream-op . c-lineup-streamop) (catch-clause . 0) (else-clause . 0) (do-while-closure . 0) (access-label . -) (substatement-label . 2) (substatement . +) (statement-case-open . 0) (statement-case-intro . +) (statement-block-intro . +) (statement . 0) (brace-entry-open . 0) (brace-list-entry . c-lineup-under-anchor) (brace-list-intro . +) (brace-list-close . 0) (brace-list-open . 0) (block-close . 0) (block-open . 0) (inher-cont . c-lineup-multi-inher) (inher-intro . +) (member-init-cont . c-lineup-multi-inher) (member-init-intro . +) (annotation-var-cont . +) (annotation-top-cont . 0) (topmost-intro . 0) (knr-argdecl . 0) (knr-argdecl-intro . +) (func-decl-cont . +) (inline-close . 0) (class-close . 0) (defun-block-intro . +) (defun-close . 0) (defun-open . 0) (c . c-lineup-C-comments) (string . c-lineup-dont-change) (topmost-intro-cont first php-lineup-cascaded-calls +) (substatement-open . 0) (label . +) (lambda-intro-cont . +) (namespace-open . 0) (inline-open . 0) (inlambda . 0) (comment-intro . 0) (class-open . 0) (case-label . +) (arglist-intro . php-lineup-arglist-intro) (arglist-cont-nonempty first php-lineup-cascaded-calls php-c-lineup-arglist) (arglist-cont first php-lineup-cascaded-calls 0) (arglist-close . php-lineup-arglist-close) (statement-cont . +))
buffer: (:length 50)
--- PHP-MODE DEBUG END ---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants