A Major Mode for Emacs, to help the editing of Samba’s configuration file smb.conf It doesn’t do anything fancy, but it helps me, I hope it helps you. It’s still a work in progress, as well as being my first non-trivial Emacs Lisp project. Comments, suggestions, and more code are welcome; email address is at the bottom of the page.
The original motivation for this was a mistake I made with my home Samba server: I commented out a section header without commenting out its settings. They therefore overrode the settings of the previous section, and caused all sorts of bizarre behaviour until I diagnosed the problem with {cs testparm}. If I’d had SMB Mode then, one touch of the TAB key would have shown me the problem.
Features
Currently smb-mode can do the following:
Auto-indent smb.conf (using TAB, “=” or “]”) and auto-pad the “=” sign.
Perform editing operations on sections (e.g. kill-section, comment-section, etc. – do a C-h m for full details)
Use outline-minor-mode appropriately to get an overview of the file.
Look up a parameter in the {cs smb.conf} manual page.
Perform parameter completion.
Toggle a yes/no parameter.
Set certain yes/no parameters explicitly (like read only) whether they exist in the current section or not.
Run the buffer through {cs testparm}.
Colour things nicely using font-lock-mode (thanks to Johnny Weare)
A list of parameters for completion is obtained from the manual page. Thus, on the first completion attempt, you will wait several seconds until the manpage is ready. You can avoid this by creating a “clean” version of the manual in a text file and setting the {cs smb-manual-file} variable; see {a href=#config Configure} below. In fact, if you are not running Emacs on a Unix system on which Samba is installed, you must do this or completion and manual lookup won’t work.
By default, SMB Mode makes the following assumptions about the format of smb.conf :
[section headers] jam left (not configurable)
options indent 3 spaces (or whatever you set {cs smb-indent} to)
comments start with ; or # and indent the same as the previous line (not configurable)
the “=” in settings always has at least one space on either side of it (set smb-pad-equal to nil to disable)
Download and Install
Download the file below, and save it somewhere in your load-path , as described below.
Download
If you have administrator privileges on your machine, or at least have access to the location where Emacs is installed, save the file in Emacs’ site-lisp directory.
Configure
Place the following lines in your .emacs :
(autoload ‘smb-mode “smb-mode” “SMB Major Mode” t)
(setq auto-mode-alist
(cons ‘(“smb\\.conf$” . smb-mode) auto-mode-alist))
This instructs Emacs that whenever a file ending in smb.conf is edited, smb-mode should be used. It also causes smb-mode.el to be automatically loaded when required, assuming that you installed it correctly as above.
Some aspects of SMB Mode’s behaviour is configurable; here are some examples of what you can put in your .emacs :
Change the automatic parameter indent to 5 (default is 3):
(setq smb-indent 5)
Change the string used to comment a line (default is
[this should probably be ; or #]:
(setq smb-comment-str “#”)
Stop the automatic padding of = characters:
(setq smb-pad-equal nil)}
Use a text file as the source of the smb.conf manual page, rather than invoking smb.conf :
(setq smb-manual-file “~/smb-manual”)
Automatically enter Outline minor mode with appropriate things defined so that outlines work properly. TAB key hides and unhides sections, as well as indenting. Not recommended until you get used to things without it.
(setq smb-use-outline-mode t)
If in outline mode as above, automatically hide all bodies and just show the headers initially. Again, not recommended until you have more experience.
(setq smb-hide-immediate t)
