Emacs自动缩进及括号匹配高亮功能失效问题求助
Hey there, sorry to hear your go-to Emacs setup went off the rails after your time away—let’s work through these glitches step by step.
Auto-Indentation Broken Across All Modes
First, let’s tackle the auto-indent problem since it’s affecting every file type:
Verify the correct major mode is active
Open a Python file (or any file you’d expect indentation for) and check the bottom status bar—does it showPython(or the relevant mode likeOrg/Java), or is it stuck onFundamental? If it’s the latter, manually activate the mode withM-x python-mode(swap for your target mode) and see if indentation kicks in. If yes, yourauto-mode-alist(which maps file extensions to modes) might have been altered. Check its current state withC-h v auto-mode-alistto confirm entries like("\\.py\\'" . python-mode)still exist.Check core indentation modes
Theelectric-indent-modehandles automatic indentation when you start a new line. Toggle it on withM-x electric-indent-mode—if indentation starts working, add(electric-indent-mode 1)to your init file to keep it enabled by default. Also, double-check variables likeindent-tabs-mode(useC-h v indent-tabs-mode)—for Python, this should benil(using spaces instead of tabs), andtab-widthshould match your expected indent size (usually 4).Rule out configuration conflicts
Launch Emacs without loading your custom config by runningemacs --no-init-filefrom the terminal. If indentation works here, the issue is in your personal init file (.emacs,.emacs.d/init.el) or a global company config that changed while you were gone. Try commenting out sections of your init file one by one, restarting Emacs each time, to pinpoint the conflicting code.
Bracket Highlighting Not Functioning
Now let’s fix the matching bracket highlight problem:
Ensure
show-paren-modeis enabled
This built-in mode is responsible for highlighting matching parentheses, brackets, and braces. Activate it withM-x show-paren-mode—if the highlighting starts working, add(show-paren-mode 1)to your init file to keep it turned on permanently.Check highlight visibility
If the mode is enabled but you can’t see the highlight, the face (color/style) might blend into your theme. Customize the face withM-x customize-face show-paren-face—adjust the background/foreground colors to a high-contrast combo, then save the changes to your init file.Test with a clean config
Useemacs --no-init-fileagain to see if bracket highlighting works here. If yes, your config has code that’s overriding or disablingshow-paren-mode—look for lines settingshow-paren-modeto0, or plugins that might interfere with bracket matching.
Bonus: Check for Emacs Version Updates
If your company updated the Emacs version while you were away, some old config syntax might be deprecated. Check your current version with M-x emacs-version—if it’s a major jump (e.g., from 26 to 29), you may need to update outdated functions or settings in your init file.
内容的提问来源于stack exchange,提问作者Ness

