emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
614 stars 160 forks source link

Indentation of "hanging" function call with namespace #1194

Open Fuco1 opened 2 years ago

Fuco1 commented 2 years ago

This is the current indent, it sort of gets confused at the :: token and thinks that's where the line "hangs".

    token <- AzureAuth::get_azure_token(
                            c("https://storage.azure.com/.default", "offline_access"),
                            tenant = "hello",
                            app = "world",
                            password = "secret",
                            version = 2
                        )

This seems much more natural to me.

    token <- AzureAuth::get_azure_token(
        c("https://storage.azure.com/.default", "offline_access"),
        tenant = "hello",
        app = "world",
        password = "secret",
        version = 2
    )

I patched a function ess-calculate-indent--args-prev-call with el-patch, notice the part wrapped with el-patch-swap which replaces your regex with my edit to simply include check against :: token. Is this something we would want to PR and just make a default, or maybe add some setting? Personally, this has been annoying me for ages and I finally just fixed it :D (took me about 3 minutes :man_facepalming: )

(el-patch-defun ess-calculate-indent--args-prev-call (block)
  ;; Handle brackets chains such as ][ (cf data.table)
  (ess-climb-chained-delims)
  ;; Handle call chains
  (if ess-indent-from-chain-start
      (while (and (ess-backward-sexp)
                  (when (looking-back (el-patch-swap
                                        "[[(][ \t,]*"
                                        (rx (or (char ?\[ ?\() "::")
                                            (* (char ?  ?    ?,))))
                                      (line-beginning-position))
                    (goto-char (match-beginning 0)))))
    (ess-backward-sexp))
  (when ess-indent-from-lhs
    (ess-climb-lhs))
  (if (and nil
           (eq block 'fun-decl)
           (not (eq arg-block 'opening))
           (not (eq (ess-offset-type type-sym) 'open-delim)))
      (+ (ess-offset 'block) (current-column))
    (current-column)))
lionel- commented 2 years ago

You can set ess-offset-arguments-newline to prev-line instead of prev-call to indent this way.

Fuco1 commented 2 years ago

Ah, they are defvar instead of defcustom so they didn't show up in the settings when I was looking around.

Would you mind me creating a PR turning them into options? (defcustom)

vspinu commented 2 years ago

I still think this is a valid issue. The call should be considered AzureAuth::get_azure_token not just get_azure_token.

token <- AzureAuth::get_azure_token(
           c("https://storage.azure.com/.default", "offline_access"),
           tenant = "hello",
           app = "world",
           password = "secret",
           version = 2)