2

In this case the basic offset is 4 and tabs mode is enabled.

For example I am getting:

if (! (true // Problem when the value starts inline.
        && false)) {} // I get two tabs, one per '('.

if (! (
    true // No problem when value does not start inline.
    && false)) {} // I get one tab as wanted.

I get one tab per (, but since they are inline, I want just one tab:

if (! (true // Problem solved.
    && false)) {} // One tab.

if (! (
    true // No problem.
    && false)) {} // One tab.

This is how I style my code:

(c-add-style
 "MyStylePHP"
 `((c-basic-offset . 4)
   (c-offsets-alist . (
                       (arglist-close . php-lineup-arglist-close)
                       (arglist-cont . (first php-lineup-cascaded-calls 0))
                       (arglist-cont-nonempty . +)
                       (arglist-intro . php-lineup-arglist-intro)
                       (case-label . +)
                       (class-open . 0)
                       (comment-intro . 0)
                       (inlambda . 0)
                       (inline-open . 0)
                       (namespace-open . 0)
                       (lambda-intro-cont . +)
                       (label . +)
                       (statement-cont . (first
                                          php-lineup-cascaded-calls
                                          php-lineup-string-cont
                                          php-lineup-hanging-semicolon +))
                       (substatement-open . 0)
                       (topmost-intro-cont . (first
                                              php-lineup-cascaded-calls +))))
   (c-indent-comments-syntactically-p . t)
   (indent-tabs-mode . t)
   (tab-width . ,(default-value 'tab-width))
   (fill-column . ,(default-value 'fill-column))
   (show-trailing-whitespace . ,(default-value 'show-trailing-whitespace))
   (php-style-delete-trailing-whitespace . nil)))

(add-hook
 'php-mode-hook
 '(lambda ()
    (c-set-style "MyStylePHP")))

1 Answer 1

1
+50

If the lineup function my-php-lineup-arglist-cont below is registered for the indentation of arglist-cont it fetches the indentation of the preceeding function statement and adds one times c-basic-offset.

Use my-php-lineup-arglist-cont as a replacement for php-lineup-cascaded-calls in the entry for arglist-cont-nonempty in your c-offsets-alist.

(require 'subr-x)
(defun my-php-lineup-arglist-cont (_langelem)
  "Indent continued arglists relatively with one `c-basic-offset'."
  (when-let ((state (car (c-guess-basic-syntax)))
         (pos (c-langelem-pos state)))
    (save-excursion
      (goto-char pos)
      (vector (+
           c-basic-offset
           (current-column))))))
3
  • I get the error "Symbol's function definition is void: when-let"
    – mikl
    Commented Jun 28, 2019 at 18:17
  • 1
    @mikl Sorry, I added (require 'subr-x). That should solve the problem. Note that the require should be wrapped with eval-when-compile in code that is byte compiled. when-let is a macro.
    – Tobias
    Commented Jun 28, 2019 at 18:19
  • Yes it works now, awesome! thanks!
    – mikl
    Commented Jun 28, 2019 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.