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

How to set indent in xml to 4? #5483

Closed
fuzihaofzh opened this issue Mar 14, 2016 · 18 comments
Closed

How to set indent in xml to 4? #5483

fuzihaofzh opened this issue Mar 14, 2016 · 18 comments

Comments

@fuzihaofzh
Copy link

I have set tab equal to 4 spaces. But when I use xml and lua mode, it turn out to set the tab as 2 spaces. How can I solve that?

@darfink
Copy link

darfink commented Mar 14, 2016

In most cases each major-mode has mode-specific options for adjusting indentation:

  • Web-mode (setq web-mode-markup-indent-offset 4)
  • Lua-mode: (setq lua-indent-level 4)
  • Nxml-mode: (setq nxml-child-indent 4 nxml-attribute-indent 4)

You may have to set tab-width as well.

@fuzihaofzh
Copy link
Author

Hi, @darfink, I tried as you said, and the user-config is as follows:

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
 This function is called at the very end of Spacemacs initialization after
layers configuration. You are free to put any user code."
  ;;(xterm-mouse-mode 0)
  (global-hl-line-mode 0)
  ;;tab
  (setq-default tab-width 4)
  (setq web-mode-markup-indent-offset 4)
  (setq lua-indent-level 4)
  (setq nxml-child-indent 4 nxml-attribute-indent 4)
  (setq-default c-basic-offset 4)
  ;;neotree
  (global-set-key (kbd "<f9>") 'neotree-toggle)
  (global-set-key (kbd "C-j") 'avy-goto-word-or-subword-1)
  (spacemacs/toggle-automatic-symbol-highlight)
  )

But it still cannot work. How could that happen?

@darfink
Copy link

darfink commented Mar 14, 2016

Have you configured a custom major-mode for XML files or are you using the default? (nxml-mode).
Using a complete vanilla version of Spacemacs I achieve the desired behavior by using:

(defun dotspacemacs/user-config ()
  (setq-default nxml-child-indent 4))

@TheBB
Copy link
Collaborator

TheBB commented Mar 14, 2016

Use setq-default, not setq. Then confirm that in the relevant buffer(s), the variables actually have the values that you expect.

@fuzihaofzh
Copy link
Author

@TheBB @darfink
This is my layer config and it seems still not work.

dotspacemacs-configuration-layers
   '(
     ;; ----------------------------------------------------------------
     ;; Example of useful layers you may want to use right away.
     ;; Uncomment some layer names and press <SPC f e R> (Vim style) or
     ;; <M-m f e R> (Emacs style) to install them.
     ;; ----------------------------------------------------------------
     osx
     python
     ipython
     c-c++
     markdown
     auto-completion
     better-defaults
     emacs-lisp
     git
     markdown
     org
     lua
     nxml
     html
     ;; (shell :variables
     ;;        shell-default-height 30
     ;;        shell-default-position 'bottom)
     spell-checking
     syntax-checking
     version-control
     ido
     smex
     gtags
     )
(defun dotspacemacs/user-config ()
  "Configuration function for user code.
 This function is called at the very end of Spacemacs initialization after
layers configuration. You are free to put any user code."
  ;;(xterm-mouse-mode 0)
  (global-hl-line-mode 0)
  ;;tab
  (setq-default tab-width 4)
  (setq-default web-mode-markup-indent-offset 4)
  (setq-default lua-indent-level 4)
  (setq-default nxml-child-indent 4 nxml-attribute-indent 4)
  (setq-default c-basic-offset 4)
  ;;neotree
  (global-set-key (kbd "<f9>") 'neotree-toggle)
  (global-set-key (kbd "C-j") 'avy-goto-word-or-subword-1)
  (spacemacs/toggle-automatic-symbol-highlight)
  )

@TheBB
Copy link
Collaborator

TheBB commented Mar 14, 2016

As I said, can you please confirm whether web-mode-markup-indent-offset actually has the value 4 in an XML file?

@TheBB
Copy link
Collaborator

TheBB commented Mar 14, 2016

Sorry, it seems xml files aren't in web-mode by default. That was a customization I had made myself.

@fuzihaofzh
Copy link
Author

@TheBB I don't have web-mode-markup-indent-offset. I ckecked lua-indent-level it's 4, but it work with still 2 indent.

@mrvon
Copy link

mrvon commented Mar 22, 2016

Yes, setq lua-indent-level can't work!
because function dotspacemacs/user-config() is run before lua-mode 's default setting function.

@fuzihaofzh
Copy link
Author

@mrvon How to run it after lua-mode's default setting function?

@mrvon
Copy link

mrvon commented Mar 26, 2016

@maplewizard Sorry, I don't know. I am a spacemacs beginner.

@slowfeel
Copy link

slowfeel commented May 5, 2016

you should change the lua-indent-level in file: layers/+lang/lua/package.el

@TheBB
Copy link
Collaborator

TheBB commented May 5, 2016

We shouldn't have that there in the first place.

@TheBB
Copy link
Collaborator

TheBB commented May 5, 2016

Fixed the lua stuff in ff8d4da at least. Now it should work in dotspacemacs/user-config.

@langston-barrett
Copy link
Contributor

Is there no 'xml-mode-hook? Here's how I do it for shell scripts.

  (defun siddharthist/sh-mode ()
    "My own personal preferences for sh-mode"
    (setq sh-basic-offset 2
          sh-indentation 2))
  (add-hook 'sh-mode-hook 'siddharthist/sh-mode)

@d12frosted
Copy link
Collaborator

@siddharthist there is nxml-mode-hook. So yeah, it's also possible to use hooks.

@d12frosted
Copy link
Collaborator

And also I can confirm that on develop branch setting nxml-child-indent to 4 works.

(defun dotspacemacs/user-config ()
  "Configuration function.
This function is called at the very end of Spacemacs initialization after
layers configuration."
  (setq nxml-child-indent 4))

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
@lebensterben lebensterben removed the stale marked as a stale issue/pr (usually by a bot) label Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Forum
  
To close
Development

No branches or pull requests

9 participants