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

Wrong indent for :bind #887

Closed
introom opened this issue Nov 29, 2020 · 5 comments
Closed

Wrong indent for :bind #887

introom opened this issue Nov 29, 2020 · 5 comments
Labels
notabug Not a bug in use-package

Comments

@introom
Copy link

introom commented Nov 29, 2020

for example, the following :bind form is not correctly indented.

(use-package org
  :bind (:map org-mode-map ("C-c C-'" . org-edit-special)
              :map org-src-mode-map ("C-c C-'" . org-edit-src-exit)))

@conao3

This comment was marked as off-topic.

@black7375
Copy link

I found a workaround here.
https://github.com/noctuid/general.el#general-keyword
https://emacs.stackexchange.com/questions/10230/how-to-indent-keywords-aligned

(defun lisp-indent-function (indent-point state)
     "This function is the normal value of the variable `lisp-indent-function'.
The function `calculate-lisp-indent' calls this to determine
if the arguments of a Lisp function call should be indented specially.
INDENT-POINT is the position at which the line being indented begins.
Point is located at the point to indent under (for default indentation);
STATE is the `parse-partial-sexp' state for that position.
If the current line is in a call to a Lisp function that has a non-nil
property `lisp-indent-function' (or the deprecated `lisp-indent-hook'),
it specifies how to indent.  The property value can be:
* `defun', meaning indent `defun'-style
  \(this is also the case if there is no property and the function
  has a name that begins with \"def\", and three or more arguments);
* an integer N, meaning indent the first N arguments specially
  (like ordinary function arguments), and then indent any further
  arguments like a body;
* a function to call that returns the indentation (or nil).
  `lisp-indent-function' calls this function with the same two arguments
  that it itself received.
This function returns either the indentation to use, or nil if the
Lisp function does not specify a special indentation."
     (let ((normal-indent (current-column))
           (orig-point (point)))
       (goto-char (1+ (elt state 1)))
       (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
       (cond
        ;; car of form doesn't seem to be a symbol, or is a keyword
        ((and (elt state 2)
              (or (not (looking-at "\\sw\\|\\s_"))
                  (looking-at ":")))
         (if (not (> (save-excursion (forward-line 1) (point))
                     calculate-lisp-indent-last-sexp))
             (progn (goto-char calculate-lisp-indent-last-sexp)
                    (beginning-of-line)
                    (parse-partial-sexp (point)
                                        calculate-lisp-indent-last-sexp 0 t)))
         ;; Indent under the list or under the first sexp on the same
         ;; line as calculate-lisp-indent-last-sexp.  Note that first
         ;; thing on that line has to be complete sexp since we are
         ;; inside the innermost containing sexp.
         (backward-prefix-chars)
         (current-column))
        ((and (save-excursion
                (goto-char indent-point)
                (skip-syntax-forward " ")
                (not (looking-at ":")))
              (save-excursion
                (goto-char orig-point)
                (looking-at ":")))
         (save-excursion
           (goto-char (+ 2 (elt state 1)))
           (current-column)))
        (t
         (let ((function (buffer-substring (point)
                                           (progn (forward-sexp 1) (point))))
               method)
           (setq method (or (function-get (intern-soft function)
                                          'lisp-indent-function)
                            (get (intern-soft function) 'lisp-indent-hook)))
           (cond ((or (eq method 'defun)
                      (and (null method)
                           (> (length function) 3)
                           (string-match "\\`def" function)))
                  (lisp-indent-defform state indent-point))
                 ((integerp method)
                  (lisp-indent-specform method state
                                        indent-point normal-indent))
                 (method
                  (funcall method indent-point state))))))))

@doolio
Copy link

doolio commented Oct 31, 2021

A workaround is to be explicit that no bindings are configured in the global keymap.

(use-package org
  :bind (nil
         :map org-mode-map
         ("C-c C-'" . org-edit-special)
         :map org-src-mode-map
         ("C-c C-'" . org-edit-src-exit)))

alexluigit added a commit to alexluigit/emacs-grandview that referenced this issue Dec 5, 2021
@skangas
Copy link
Collaborator

skangas commented Nov 27, 2022

You could also rely on the fact that a recent Emacs indents this correctly when you add a space character:

(use-package org
  :bind ( :map org-mode-map
          ("C-c C-'" . org-edit-special)
          :map org-src-mode-map
          ("C-c C-'" . org-edit-src-exit)))

@skangas
Copy link
Collaborator

skangas commented Nov 29, 2022

Given how Emacs currently works, I don't think we can do much better than starting with a space, as I suggested in the previous comment. If any change is to take place, it should be made in Emacs itself, and the place to discuss that is not here.

As unsatisfying as it may be, I'm therefore closing this issue now. Thanks.

@skangas skangas closed this as completed Nov 29, 2022
@skangas skangas added the notabug Not a bug in use-package label Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notabug Not a bug in use-package
Projects
None yet
Development

No branches or pull requests

5 participants