Can't control width of sr-speedbar - emacs

I'm using emacs with sr-speedbar, but can't control its width. When I resize the emacs window, the sr-speedbar always expands with it. I have tried this both with xemacs and emacs.
My .emacs file below:
(require 'package)
(package-initialize)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")))
(setq c-default-style "linux"
c-basic-offset 4)
(iswitchb-mode 1)
(setq inhibit-splash-screen t)
(load-theme 'zenburn t)
(require 'ecb)
(setq stack-trace-on-error t)
(desktop-save-mode 1)
;(defun toggle-fullscreen ()
; (interactive)
; (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
; '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
; (x-send-client-message nil 0 nil "_NET_WM_STATE" 32
; '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
;)
;(toggle-fullscreen)
(require 'sr-speedbar)
(setq
sr-speedbar-right-side nil
sr-speedbar-width-x 10
sr-speedbar-width-console 10
sr-speedbar-max-width 10
sr-speedbar-delete-windows t)
(sr-speedbar-open)
(put 'dired-find-alternate-file 'disabled nil)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
;; Single char cursor movement. (assuming you are on qwerty)
(global-set-key (kbd "M-j") 'backward-char)
(global-set-key (kbd "M-l") 'forward-char)
(global-set-key (kbd "M-i") 'previous-line)
(global-set-key (kbd "M-k") 'next-line)
(global-set-key (kbd "M-SPC") 'set-mark-command)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes (quote ("d63e19a84fef5fa0341fa68814200749408ad4a321b6d9f30efc117aeaf68a2e" default)))
'(ecb-options-version "2.40"))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

It consumes variables at load time, not when open.
The sr-speedbar-width-* should be set before the script loaded.

This does not work, because the variables sr-speedbar-width-x and sr-speedbar-width-console do not exist any more. They have been removed from the code on 03 Aug 2014. See here: https://www.emacswiki.org/emacs/download/sr-speedbar.el
The information that you probably found on https://www.emacswiki.org/emacs/SrSpeedbar is outdated.
There is only one variable sr-speedbar-width
The variable is "consumed" when sr-speedbar-open is called. The user can define the variable before or after loading the library. This is due to the behaviour of the Emacs Lisp special form defvar (line 364), which does not overwrite the variable. For more information on this see here: https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Variables.html

Related

Emacs ignoring setq for line numbers

I am trying to set up my .emacs to use relative line numbering, and so I have included:
(setq display-line-numbers 'relative)
to my .emacs, however this is being ignored on load. Line numbers appear, however they are simply absolute line numbers, as opposed to relative.
Interestingly, when I run M-x load-file .emacs, it actually evaluates this line (as well as the rest of the file) and the line numbers become relative, however this doesn't happen the first time.
Below is my entire .emacs, and the line in question is on line 95/96:
(package-initialize)
(load "~/.emacs.rc/rc.el")
(load "~/.emacs.rc/misc-rc.el")
(defun rc/get-default-font ()
(cond
((eq system-type 'windows-nt) "Consolas-13")
((eq system-type 'gnu/linux) "Iosevka-24")))
(add-to-list 'default-frame-alist `(font . ,(rc/get-default-font)))
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
(column-number-mode 1)
(show-paren-mode 1)
(rc/require-theme 'gruber-darker)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
'(svelte-mode tramp-mode elixir-mode evil move-text nasm-mode company yasnippet multiple-cursors magit haskell-mode ido-completing-read+ smex gruber-darker-theme dash-functional dash)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(eval-after-load 'zenburn
(set-face-attribute 'line-number nil :inherit 'default))
(rc/require 'smex 'ido-completing-read+)
(require 'ido-completing-read+)
(ido-mode 1)
(ido-everywhere 1)
(ido-ubiquitous-mode 1)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;;; C mode
(setq-default c-basic-offset 4
c-default-style '((java-mode . "java")
(awk-mode . "awk")
(other . "bsd")))
(add-hook 'c-mode-hook (lambda ()
(interactive)
(c-toggle-comment-style -1)))
;;; Elisp
(add-hook 'emacs-lisp-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-j")
(quote eval-print-last-sexp))))
(add-to-list 'auto-mode-alist '("Cask" . emacs-lisp-mode))
;;; Haskell mode
(rc/require 'haskell-mode)
(setq haskell-process-type 'cabal-new-repl)
(setq haskell-process-log t)
(add-hook 'haskell-mode-hook 'haskell-ident-mode)
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(add-hook 'haskell-mode-hook 'haskell-doc-mode)
(add-hook 'haskell-mode-hook 'hindent-mode)
;;; Whitespace mode
(defun rc/set-up-whitespace-handling ()
(interactive)
(whitespace-mode 1)
(add-to-list 'write-file-fucntions 'delete-trailing-whitespace))
(add-hook 'c++-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'java-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'emacs-lisp-mode 'rc/set-up-whitespace-handling)
(add-hook 'rust-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'haskell-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'python-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'erlang-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'asm-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'nasm-mode-hook 'rc/set-up-whitespace-handling)
(global-display-line-numbers-mode)
(setq display-line-numbers 'relative)
;;; Magit
(rc/require 'cl-lib)
(rc/require 'magit)
(setq magit-auto-revert-mode nil)
(global-set-key (kbd "C-c m s") 'magit-status)
(global-set-key (kbd "C-c m l") 'magit-log)
;;; Multiple Cursors
(rc/require 'multiple-cursors)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-set-key (kbd "C-\"") 'mc/skip-to-next-like-this)
(global-set-key (kbd "C-:") 'mc/skip-to-previous-like-this)
;;; Dired
(require 'dired-x)
(setq dired-omit-files
(concat dired-omit-files "\\|^\\..+$"))
(setq-default dired-dwim-target t)
(setq dired-listing-switches "-alh")
;;; Yasnippet
(rc/require 'yasnippet)
(require 'yasnippet)
(setq yas/triggers-in-field nil)
(setq yas-snipped-dirs '("~/.emacs.snippets/"))
(yas-global-mode 1)
;;; Word-Wrap
(defun rc/enable-word-wrap ()
(interactive)
(toggle-word-wrap 1))
(add-hook 'markdown-mode-hook 'rc/enable-word-wrap)
;;; Company Mode
(rc/require 'company)
(require 'company)
(global-company-mode)
;;; NASM mode
(rc/require 'nasm-mode)
(add-to-list 'auto-mode-alist '("\\.asm\\'" . nasm-mode))
;;; TeX mode
(add-hook 'tex-mode-hook
(lambda ()
(interactive)
(add-to-list 'tex-verbatim-environments "code")))
;;; Move Text
(rc/require 'move-text)
(global-set-key (kbd "M-p") 'move-text-up)
(global-set-key (kbd "M-n") 'move-text-down)
(rc/require
'rust-mode
'markdown-mode
'elixir-mode
'svelte-mode
)
;;; Svelte Mode
(add-to-list 'auto-mode-alist '("\\.svelte\\'" . svelte-mode))
;;; Kill all buffers
(defun kill-all-buffers ()
(interactive)
(dolist (cur (buffer-list))
(kill-buffer cur)))
(defun close-current-buffer ()
(interactive)
(kill-buffer (buffer-name)))
(global-set-key (kbd "C-x K") 'kill-all-buffers)
(global-set-key (kbd "C-S-w") 'close-current-buffer)
(defun indent-whole-file ()
(interactive)
(indent-region (point-min) (point-max)))
(global-set-key (kbd "C-<tab>") 'indent-whole-file)
(global-set-key (kbd "C-=") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
Did you read this part of the doc for display-line-numbers:
This variable automatically becomes buffer-local when set outside Custom.
However, setting it through Custom sets the default value.
You're using setq with a user option - not a great idea in general. Use M-x customize-option instead, or use function customize-set-variable or custom-set-variables.
Unless you do some tricky finagling, you can't depend on your setq being evaluated in any particular buffer. And anyway, you apparently want to set the default value of the option. setq-default sets the default value of a variable. But anyway, use one of the custom* functions or (even better), M-x customize-option.
You need to use display-line-numbers-type instead as per the documentation
"The command M-x display-line-numbers-mode provides a convenient way to turn on display of line numbers. This mode has a globalized variant, global-display-line-numbers-mode. The user option display-line-numbers-type controls which sub-mode of line-number display, described above, these modes will activate."
So following works.
(global-display-line-numbers-mode 1)
(setq display-line-numbers-type 'relative)

Why is my newline taking 4 spaces by default?

I have set c-basic-offset & c-basic-indent to 4 expecting it to indent newlines after brackets only in C/C++ files. But the issue I'm facing is every newline in ".txt" document is taking 4 spaces by default which I don't want.
Here is my init.el file
(global-display-line-numbers-mode 1)
(set-frame-font "JetBrains Mono-11" nil t)
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
(setq c-basic-offset 4)
(setq c-basic-indent 4)
;(setq-default c-basic-offset 4)
;(c-set-offset 'substatement-open 0)
; stop creating backup files
(setq make-backup-files nil)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(setq recentf-max-saved-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
;; start the initial frame maximized
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
;; start every frame maximized
(add-to-list 'default-frame-alist '(fullscreen . maximized))
Please help me get rid of 4 space characters in a normal text file.
You can make your settings specific for mode. In your case if you want indentation settings to apply only for C/C++ files, you need to apply these settings for that mode hook. There are various ways of doing it, one of them is using defining those settings in a defun and add that defun to appropriate hook.
Example below shows to setup c-basic-offset and c-basic-indent to 4.
(defun my-c-mode-common-hook ()
;; my customizations for all of c-mode and related modes
(setq c-basic-offset 4)
(setq c-basic-indent 4)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(define-error (quote gv-invalid-place) "%S is not a valid place expression")

When I load emacs, it gives me this error using --debug-init after adding cl-lib.el:
Debugger entered--Lisp error: (void-function gv-define-simple-setter)
(gv-define-simple-setter buffer-file-name set-visited-file-name t)
eval-buffer(#<buffer *load*<2>> nil "d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" nil t) ; Reading at buffer position 23391
load-with-code-conversion("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" "d:/Tools/Emacs-24.3/cl-lib/cl-lib.el" nil nil)
load("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el")
mapc(load ("d:/Tools/Emacs-24.3/cl-lib/cl-lib.el"))
eval-buffer(#<buffer *load*> nil "c:/Users/Psalm3_3/.emacs" nil t) ; Reading at buffer position 76
load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
load("~/.emacs" t t)
#[0 "\205\262
This is the gv.el file I am using:
https://github.com/emacs-mirror/emacs/blob/master/lisp/emacs-lisp/gv.el
Does anyone have any suggestions? TIA.
UPDATE:
Here is the original error I was getting:
Debugger entered--Lisp error: (file-error "Cannot open load file" "cl-lib")
require(cl-lib)
eval-buffer(#<buffer *load*<2>> nil "d:/Tools/emacs-24.3/site-lisp/desktop.el" nil t) ; Reading at buffer position 5870
load-with-code-conversion("d:/Tools/emacs-24.3/site-lisp/desktop.el" "d:/Tools/emacs-24.3/site-lisp/desktop.el" nil nil)
load("d:/Tools/emacs-24.3/site-lisp/desktop.el")
mapc(load ("d:/Tools/emacs-24.3/site-lisp/desktop.el"))
eval-buffer(#<buffer *load*> nil "c:/Users/Psalm3_3/.emacs" nil t) ; Reading at buffer position 549
load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
load("~/.emacs" t t)
#[0 "\205\262
Here is my .emacs file:
(mapc 'load (file-expand-wildcards "D:/Tools/Emacs-24.3/cl-lib/cl-lib.el"))
;; Require Common Lisp. (cl in <=24.2, cl-lib in >=24.3.)
(if (require 'cl-lib nil t)
(progn
(defalias 'cl-block-wrapper 'identity)
(defalias 'member* 'cl-member)
(defalias 'adjoin 'cl-adjoin))
;; Else we're on an older version so require cl.
(require 'cl))
;; Load lisp files on start
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/flymake.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/csharp-mode.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/desktop.el"))
(mapc 'load (file-expand-wildcards "D:/Tools/emacs-24.3/site-lisp/session.el"))
;; setup load-path
(add-to-list 'load-path "D:/Tools/emacs-24.3/site-lisp")
;; TABS for C
(setq-default c-indent-tabs-mode t ; Pressing TAB should cause indentation
c-indent-level 4 ; A TAB is equivilent to four spaces
c-argdecl-indent 0 ; Do not indent argument decl's extra
c-tab-always-indent t
backward-delete-function nil) ; DO NOT expand tabs when deleting
(c-add-style "my-c-style" '((c-continued-statement-offset 4))) ; If a statement continues on the next line, indent the continuation by 4
(defun my-c-mode-hook ()
(c-set-style "my-c-style")
(c-set-offset 'substatement-open '0) ; brackets should be at same indentation level as the statements they open
(c-set-offset 'inline-open '+)
(c-set-offset 'block-open '+)
(c-set-offset 'brace-list-open '+) ; all "opens" should be indented by the c-indent-level
(c-set-offset 'case-label '+)) ; indent case labels by c-indent-level, too
(require 'csharp-mode)
(setq auto-mode-alist
(append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
(defun my-csharp-mode-fn ()
"function that runs when csharp-mode is initialized for a buffer."
(setq default-tab-width 4)
; Set indentation level to 4 spaces (instead of 2)
(setq c-basic-offset 4)
; Set the extra indentation before a substatement (e.g. the opening brace in
; the consequent block of an if statement) to 0 (instead of '+)
(c-set-offset 'substatement-open 0)
(setq-default c-basic-offset 4)
)
(add-hook 'csharp-mode-hook 'my-csharp-mode-fn t)
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-hook 'c++-mode-hook 'my-c-mode-hook)
(global-set-key "\C-cg" 'goto-line)
(global-set-key "\C-cy" '(lambda ()
(interactive)
(popup-menu 'yank-menu)))
(put 'upcase-region 'disabled nil)
;; Always use spaces instead of tabs
(setq-default indent-tabs-mode nil)
(defun FindNextDbl ()
"move to next doubled word, ignoring <...> tags" (interactive)
(re-search-forward "\\<\\([z-z]+\\)\\([\\n \\t]\\|<[^>]+>\\)+\\1\\?"))
(define-key global-map "\C-x\C-d" 'FindNextDbl)
;; Search all open buffers
(defun my-multi-occur-in-matching-buffers (regexp &optional allbufs)
"Show all lines matching REGEXP in all buffers."
(interactive (occur-read-primary-args))
(multi-occur-in-matching-buffers ".*" regexp))
(global-set-key (kbd "M-s /") 'my-multi-occur-in-matching-buffers)
(setq x-select-enable-clipboard t)
;; Copy list of all open buffers to clipboard: see http://stackoverflow.com/questions/10537265/emacs-save-current-buffer-list-to-a-text-file
(defun copy-open-files ()
"Add paths to all open files to kill ring"
(interactive)
(kill-new (mapconcat 'identity
(delq nil (mapcar 'buffer-file-name (buffer-list)))
"\n"))
(message "List of files copied to kill ring"))
;; save my desktop
(desktop-save-mode 1)
;; auto-reload modified files
(global-auto-revert-mode t)
;; put save files in back dir (see http://www.emacswiki.org/emacs/BackupDirectory)
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist
'(("." . "~/.saves")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t) ; use versioned backups
;; move to window based on arrow keys
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
;; incremental completion
(require 'helm-config)
(helm-mode 1)
;; http://stackoverflow.com/questions/275842/is-there-a-repeat-last-command-in-emacs
(defun describe-last-function()
(interactive)
(describe-function last-command))
;; get path of present buffer, see http://stackoverflow.com/questions/3669511/the-function-to-show-current-files-full-path-in-mini-buffer
(defun show-file-name ()
"Show the full path file name in the minibuffer."
(interactive)
(message (buffer-file-name)))
(global-set-key [C-f1] 'show-file-name) ; Or any other key you want
;; generate guids
(require 'guid)
UPDATE 2:
Thank you for the excellent post, #Thomas. This is what I've updated the start of my .emacs file to:
;; setup load-path
(add-to-list 'load-path "C:/Tools/emacs-24.3/site-lisp/gv.el")
(require 'gv)
(add-to-list 'load-path "D:/Tools/Emacs-24.3/cl-lib")
(add-to-list 'load-path "C:/Tools/emacs-24.3/site-lisp")
;; Load lisp files on start
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/flymake.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/csharp-mode.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/desktop.el"))
(mapc 'load (file-expand-wildcards "C:/Tools/emacs-24.3/site-lisp/session.el"))
Now this is the error I'm getting:
Debugger entered--Lisp error: (void-variable defun-declarations-alist)
(assq (quote gv-expander) defun-declarations-alist)
(or (assq (quote gv-expander) defun-declarations-alist) (let ((x (\` (gv-expander (\, (apply-partially ... ...)))))) (push x macro-declarations-alist) (push x defun-declarations-alist)))
eval-buffer(#<buffer *load*<2>> nil "d:/Tools/Emacs-24.3/site-lisp/gv.el" nil t) ; Reading at buffer position 8332
load-with-code-conversion("d:/Tools/Emacs-24.3/site-lisp/gv.el" "d:/Tools/Emacs-24.3/site-lisp/gv.el" nil t)
require(gv)
eval-buffer(#<buffer *load*> nil "c:/Users/Psalm3_3/.emacs" nil t) ; Reading at buffer position 96
load-with-code-conversion("c:/Users/Psalm3_3/.emacs" "c:/Users/Psalm3_3/.emacs" t t)
load("~/.emacs" t t)
#[0 "\205\262
Sorry, I'm pretty new at LISP.
The code you have for cl-lib looks very weird. If you have Emacs≥24.3 then you already have cl-lib builtin. And if you have something older then you can't use Emacs-24.3's cl-lib (you have to use GNU ELPA's cl-lib instead, but if it's sufficiently older you won't have GNU ELPA support builtin either, so all in all you're better up upgrading your Emacs to 24.3 or more recent).
If your Emacs is 24,1 or 24.2, then I recommend you just install cl-lib via M-x package-install RET and then add
(package-initialize)
at the beginning of your ~/.emacs which will properly setup autoloads for those packages you install via package.el (such as cl-lib above).
The block that starts with (if (require 'cl-lib ...) ...) looks like an ugly hack to work around a problem you mis-understood. Just remove it.
Also, remove flymake.el and desktop.el from your site-lisp, the version that comes with Emacs is probably more up-to-date.
The error stems from Emacs not being able to load the right files. You're trying to load a bunch of single files manually here. However, this is not the way the underlying packages are supposed to be loaded.
Usually, packages come with installation instructions that typically require you to add some lines to your init file: amending the load-path, setting up conditions for when to load the package, and adding a command how to load the package. Hardly ever does any of this ever involve a direct call of the load function which is quite low-level.
If you look at your original error, the stack trace tells you that it's thrown by (require cl-lib). require is one of the mechanisms by which Emacs loads files when necessary. For it to work, you don't need to load the file in question directly. All you have to do is set up your load-path so that Emacs can find the file that is referred to.
For instance, for your cl-lib.el file, you could do this like so:
(add-to-list 'load-path "D:/Tools/Emacs-24.3/cl-lib")
You add this line to your init file (and of course at a point before Emacs tries to load cl-lib).
The counter-part to require is provide. If you look at source code for gv.el and scroll all the way to the bottom, you'll find as the last line:
(provide 'gv)
This means that his file provides the "feature" gv, and whenever you write (require 'gv) you're telling Emacs that you need that feature. If Emacs already knows about it, all is fine and dandy; if not, Emacs will try to load that feature. So, to load the contents of the gv.el file, all you have to do is add the following to your init file:
(add-to-list 'load-path "/path/to/directory/containing/gv.el")
(require 'gv)
See the Emacs Manual for more information on require and provide.
But let me reiterate one point from above: usually, packages come with specific installation instructions, often somewhat "hidden" in a long comment-section at the top of the source code file. So, make sure to check for such instructions whenever you want to manually add a package to your setup.
On a side note:
(mapc 'load <something>)
only really makes sense if <something> expands into a list of files. If, like in your case, <something> is just a single file, you might as well just write:
(load <something>)
But again, load is a low-level function that you hardly ever need as an end-user.

I cannot get structure members in auto-completion or tooltips

I want autocomplete or company to work with C code and I need structure context level autocomplete i.e if I have a struct:
typefdef struct HOST_ {
IP4_ADDRESS ip4;
IP6_ADDRESS ip6;
MAC_ADDRESS mac;
} HOST;
... and then I have code:
HOST host;
host->
Then if I hit tab then I should get a drop down menu giving me all the (and only the) three options.
This is what I did:
(defun my-tab-del-commands(key-map)
"This function sets the <tab> and <backspace> keymaps according to the special commands
that I have set. This needs to be set per mode keymap where it is needed. We cannot
use the global keymap because that would override command completion in minibuffer"
;; Set TAB in major-mode keymap to "tab-to-tab" stop
;; Use tab2tab stop and not just add +4 spaces (tab stop defined by tag-stop-list)
(define-key key-map (kbd "<tab>") 'tab-to-tab-stop)
;; Define Key for <backtab>
(define-key key-map (kbd "<S-tab>") 'backward-move-to-tab-stop)
(define-key key-map (kbd "<backtab>") 'backward-move-to-tab-stop)
;; Define C-tab as my-indent-system
(define-key key-map (kbd "<C-tab>") 'my-indent-system)
;; Also provide a duplicate "\C-ci" in case C-TAB is overridden by any minor mode
(define-key emacs-lisp-mode-map "\C-ci" 'my-indent-system)
;; Shift backspace moves by one tab stop till no more whitespace
(define-key key-map (kbd "<S-backspace>") 'backspace-whitespace-to-tab-stop)
;; Alt backspace is c-hungry-delete-backwards
(define-key key-map (kbd "<M-backspace>") 'c-hungry-delete-backwards)
)
;; Simple Backend of semantic with ede as project manager
;; Lets try semantic (CDET) backend for now only.
;; Later learn clang or rtags or other big stuff to handle the whole project
(defun backend:semantic-ede ()
"Setup for semantic-mode with ede as project management.
Simple stuff for starters"
(semantic-mode 1)
(global-semanticdb-minor-mode 1)
(global-semantic-idle-scheduler-mode 1)
(setq-mode-local c-mode semanticdb-find-default-throttle
'(project unloaded system recursive))
(semantic-add-system-include my-lp-build-path)
(semanticdb-enable-gnu-global-databases 'c-mode t)
(semanticdb-enable-gnu-global-databases 'c++-mode t)
(require 'ede)
(global-ede-mode)
(let ((makefile (format "%s/Makefile" my-mp-source-path)))
(when (file-exists-p makefile)
(ede-cpp-root-project "openflow" :file makefile)))
)
;; There are two "schools of thought" of intelligent autocomplete
;; (a) auto-complete package and (b) company package.
;; This is auto-complete
(defun completion:auto-complete ()
"Setup auto-complete with triggers. We still need to hook with C mode"
;; Then autocomplete
(require 'auto-complete)
(require 'auto-complete-config)
(global-auto-complete-mode t)
;; auto complete mod
;; should be loaded after yasnippet so that they can work together
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
;; set the trigger key so that it can work together with yasnippet on tab key,
;; if the word exists in yasnippet, pressing tab will cause yasnippet to
;; activate, otherwise, auto-complete will
(ac-set-trigger-key "TAB")
(ac-set-trigger-key "<tab>")
(global-auto-complete-mode t)
)
(defun my-smart-c-auto-complete()
;; Now tie up autocomplete with semantic
;; Later hook it up to c-mode-hook via c-mode-config func
(require 'auto-complete-c-headers)
(add-to-list 'ac-sources 'ac-source-words-in-same-mode-buffers)
(add-to-list 'ac-sources 'ac-source-dictionary)
(add-to-list 'ac-sources 'ac-source-abbrev)
(add-to-list 'ac-sources 'ac-source-semantic)
(add-to-list 'ac-sources 'ac-source-c-headers)
)
;; This is company
(defun completion:company ()
"Setup comany mode"
(require 'company)
(add-hook 'after-init-hook 'global-company-mode)
)
(defun tab-side-story ()
(interactive)
;; First load and init Yasnippet - This sets the TAB first to Ysnippet
;; This will work on LISP & SHELL SCRIPTS also
;; (require 'yasnippet)
;; (yas-global-mode 1)
;; Second, use whatever completion mechanism you wanna use auto-complete or company
;; This will work on LISP also!
;;(completion:auto-complete)
(completion:company)
;; Then this function sets tab command
(my-tab-del-commands c-mode-base-map)
)
;; Completion mechanism needs a backend
(backend:semantic-ede)
(tab-side-story)
;; define My Great C style with linux as the parent style (choose google if you wish)
(c-add-style "my-great-c-style"
'("linux" ; use linux as parent style
(indent-tabs-mode . nil) ; tabs are spaces
(c-syntactic-indentation . t) ; auto-syntax
(c-syntactic-indentation-in-macros . t) ; ditto for macros
(c-tab-always-indent . nil) ; Otherwise our complex TAB will not work!
(tab-width . 4) ; if there is a <tab> expand to 4 spaces
(backward-delete-function . nil) ; DO NOT expand tabs when deleting
(c-continued-statement-offset . 4))) ;continued statement offset 4
(defun my-c-mode-config ()
(c-set-style "my-great-c-style")
(when (= emacs-major-version 23)
(gtags-mode 1))
(when (= emacs-major-version 24)
(tab-side-story)
;; (my-smart-c-auto-complete)
(ggtags-mode 1)
(setq ggtags-update-on-save nil))
(electric-indent-mode)
(setq c-basic-offset 4)
(setq c-tab-always-indent nil))
;; Needs to be hooked - do it here instead of common area
(add-hook 'c-mode-hook 'my-c-mode-config)
Sorry for the very long code but most of them are my comments and notes jotted down so far less "code" than it seems. In this I have set it for company mode though I have auto-complete.
Both are not working! Something is clashing with something.

What's in your .emacs?

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I've switched computers a few times recently, and somewhere along the way I lost my .emacs. I'm trying to build it up again, but while I'm at it, I thought I'd pick up other good configurations that other people use.
So, if you use Emacs, what's in your .emacs?
Mine is pretty barren right now, containing only:
Global font-lock-mode! (global-font-lock-mode 1)
My personal preferences with respect to indentation, tabs, and spaces.
Use cperl-mode instead of perl-mode.
A shortcut for compilation.
What do you think is useful?
Use the ultimate dotfiles site. Add your '.emacs' here. Read the '.emacs' of others.
My favorite snippet. The ultimate in Emacs eye candy:
;; real lisp hackers use the lambda character
;; courtesy of stefan monnier on c.l.l
(defun sm-lambda-mode-hook ()
(font-lock-add-keywords
nil `(("\\<lambda\\>"
(0 (progn (compose-region (match-beginning 0) (match-end 0)
,(make-char 'greek-iso8859-7 107))
nil))))))
(add-hook 'emacs-lisp-mode-hook 'sm-lambda-mode-hook)
(add-hook 'lisp-interactive-mode-hook 'sm-lamba-mode-hook)
(add-hook 'scheme-mode-hook 'sm-lambda-mode-hook)
So you see i.e. the following when editing lisp/scheme:
(global-set-key "^Cr" '(λ () (interactive) (revert-buffer t t nil)))
I have this to change yes or no prompt to y or n prompts:
(fset 'yes-or-no-p 'y-or-n-p)
I have these to start Emacs without so much "fanfare" which I got from this question.
(setq inhibit-startup-echo-area-message t)
(setq inhibit-startup-message t)
And Steve Yegge's function to rename a file that you're editing along with its corresponding buffer:
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)
(progn
(rename-file name new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil))))))
One thing that can prove very useful: Before it gets too big, try to split it into multiple files for various tasks: My .emacs just sets my load-path and the loads a bunch of files - I've got all my mode-specific settings in mode-configs.el, keybindings in keys.el, et cetera
My .emacs is only 127 lines, here are the most useful little snippets:
;; keep backup files neatly out of the way in .~/
(setq backup-directory-alist '(("." . ".~")))
This makes the *~ files which I find clutter up the directory go into a special directory, in this case .~
;; uniquify changes conflicting buffer names from file<2> etc
(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator "/")
(setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
(setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers
This sets up uniquify which changes those ugly file<2> etc. buffer names you get when multiple files have the same name into a much neater unambiguous name using as much of the whole path of the file as it has to.
That's about it... the rest is pretty standard stuff that I'm sure everyone knows about.
This is not the whole kit and kaboodle, but it is some of the more useful snippets I've gathered:
(defadvice show-paren-function (after show-matching-paren-offscreen
activate)
"If the matching paren is offscreen, show the matching line in the
echo area. Has no effect if the character before point is not of
the syntax class ')'."
(interactive)
(let ((matching-text nil))
;; Only call `blink-matching-open' if the character before point
;; is a close parentheses type character. Otherwise, there's not
;; really any point, and `blink-matching-open' would just echo
;; "Mismatched parentheses", which gets really annoying.
(if (char-equal (char-syntax (char-before (point))) ?\))
(setq matching-text (blink-matching-open)))
(if (not (null matching-text))
(message matching-text))))
;;;;;;;;;;;;;;;
;; UTF-8
;;;;;;;;;;;;;;;;;;;;
;; set up unicode
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; This from a japanese individual. I hope it works.
(setq default-buffer-file-coding-system 'utf-8)
;; From Emacs wiki
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;; Wwindows clipboard is UTF-16LE
(set-clipboard-coding-system 'utf-16le-dos)
(defun jonnay-timestamp ()
"Spit out the current time"
(interactive)
(insert (format-time-string "%Y-%m-%d")))
(defun jonnay-sign ()
"spit out my name, email and the current time"
(interactive)
(insert "-- Jonathan Arkell (jonathana#criticalmass.com)")
(jonnay-timestamp))
;; Cygwin requires some seriosu setting up to work the way i likes it
(message "Setting up Cygwin...")
(let* ((cygwin-root "c:")
(cygwin-bin (concat cygwin-root "/bin"))
(gambit-bin "/usr/local/Gambit-C/4.0b22/bin/")
(snow-bin "/usr/local/snow/current/bin")
(mysql-bin "/wamp/bin/mysql/mysql5.0.51a/bin/"))
(setenv "PATH" (concat cygwin-bin ";" ;
snow-bin ";"
gambit-bin ";"
mysql-bin ";"
".;")
(getenv "PATH"))
(setq exec-path (cons cygwin-bin exec-path)))
(setq shell-file-name "bash")
(setq explicit-shell-file-name "bash")
(require 'cygwin-mount)
(cygwin-mount-activate)
(message "Setting up Cygwin...Done")
; Completion isn't perfect, but close
(defun my-shell-setup ()
"For Cygwin bash under Emacs 20+"
(setq comint-scroll-show-maximum-output 'this)
(setq comint-completion-addsuffix t)
(setq comint-eol-on-send t)
(setq w32-quote-process-args ?\")
(make-variable-buffer-local 'comint-completion-addsuffix))
(setq shell-mode-hook 'my-shell-setup)
(add-hook 'emacs-startup-hook 'cygwin-shell)
; Change how home key works
(global-set-key [home] 'beginning-or-indentation)
(substitute-key-definition 'beginning-of-line 'beginning-or-indentation global-map)
(defun yank-and-down ()
"Yank the text and go down a line."
(interactive)
(yank)
(exchange-point-and-mark)
(next-line))
(defun kill-syntax (&optional arg)
"Kill ARG sets of syntax characters after point."
(interactive "p")
(let ((arg (or arg 1))
(inc (if (and arg (< arg 0)) 1 -1))
(opoint (point)))
(while (not (= arg 0))
(if (> arg 0)
(skip-syntax-forward (string (char-syntax (char-after))))
(skip-syntax-backward (string (char-syntax (char-before)))))
(setq arg (+ arg inc)))
(kill-region opoint (point))))
(defun kill-syntax-backward (&optional arg)
"Kill ARG sets of syntax characters preceding point."
(interactive "p")
(kill-syntax (- 0 (or arg 1))))
(global-set-key [(control shift y)] 'yank-and-down)
(global-set-key [(shift backspace)] 'kill-syntax-backward)
(global-set-key [(shift delete)] 'kill-syntax)
(defun insert-file-name (arg filename)
"Insert name of file FILENAME into buffer after point.
Set mark after the inserted text.
Prefixed with \\[universal-argument], expand the file name to
its fully canocalized path.
See `expand-file-name'."
;; Based on insert-file in Emacs -- ashawley 2008-09-26
(interactive "*P\nfInsert file name: ")
(if arg
(insert (expand-file-name filename))
(insert filename)))
(defun kill-ring-save-filename ()
"Copy the current filename to the kill ring"
(interactive)
(kill-new (buffer-file-name)))
(defun insert-file-name ()
"Insert the name of the current file."
(interactive)
(insert (buffer-file-name)))
(defun insert-directory-name ()
"Insert the name of the current directory"
(interactive)
(insert (file-name-directory (buffer-file-name))))
(defun jonnay-toggle-debug ()
"Toggle debugging by toggling icicles, and debug on error"
(interactive)
(toggle-debug-on-error)
(icicle-mode))
(defvar programming-modes
'(emacs-lisp-mode scheme-mode lisp-mode c-mode c++-mode
objc-mode latex-mode plain-tex-mode java-mode
php-mode css-mode js2-mode nxml-mode nxhtml-mode)
"List of modes related to programming")
; Text-mate style indenting
(defadvice yank (after indent-region activate)
(if (member major-mode programming-modes)
(indent-region (region-beginning) (region-end) nil)))
I have a lot of others that have already been mentioned, but these are absolutely necessary in my opinion:
(transient-mark-mode 1) ; makes the region visible
(line-number-mode 1) ; makes the line number show up
(column-number-mode 1) ; makes the column number show up
You can look here: http://www.dotemacs.de/
And my .emacs is pretty long to put it here as well, so it will make the answer not too readable. Anyway, if you wish I can sent it to you.
Also I would recomend you to read this: http://steve.yegge.googlepages.com/my-dot-emacs-file
Here are some key mappings that I've become dependent upon:
(global-set-key [(control \,)] 'goto-line)
(global-set-key [(control \.)] 'call-last-kbd-macro)
(global-set-key [(control tab)] 'indent-region)
(global-set-key [(control j)] 'join-line)
(global-set-key [f1] 'man)
(global-set-key [f2] 'igrep-find)
(global-set-key [f3] 'isearch-forward)
(global-set-key [f4] 'next-error)
(global-set-key [f5] 'gdb)
(global-set-key [f6] 'compile)
(global-set-key [f7] 'recompile)
(global-set-key [f8] 'shell)
(global-set-key [f9] 'find-next-matching-tag)
(global-set-key [f11] 'list-buffers)
(global-set-key [f12] 'shell)
Some other miscellaneous stuff, mostly for C++ development:
;; Use C++ mode for .h files (instead of plain-old C mode)
(setq auto-mode-alist (cons '("\\.h$" . c++-mode) auto-mode-alist))
;; Use python-mode for SCons files
(setq auto-mode-alist (cons '("SConstruct" . python-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("SConscript" . python-mode) auto-mode-alist))
;; Parse CppUnit failure reports in compilation-mode
(require 'compile)
(setq compilation-error-regexp-alist
(cons '("\\(!!!FAILURES!!!\nTest Results:\nRun:[^\n]*\n\n\n\\)?\\([0-9]+\\)) test: \\([^(]+\\)(F) line: \\([0-9]+\\) \\([^ \n]+\\)" 5 4)
compilation-error-regexp-alist))
;; Enable cmake-mode from http://www.cmake.org/Wiki/CMake_Emacs_mode_patch_for_comment_formatting
(require 'cmake-mode)
(setq auto-mode-alist
(append '(("CMakeLists\\.txt\\'" . cmake-mode)
("\\.cmake\\'" . cmake-mode))
auto-mode-alist))
;; "M-x reload-buffer" will revert-buffer without requiring confirmation
(defun reload-buffer ()
"revert-buffer without confirmation"
(interactive)
(revert-buffer t t))
To refresh the webpage you're editing from within Emacs
(defun moz-connect()
(interactive)
(make-comint "moz-buffer" (cons "127.0.0.1" "4242"))
(global-set-key "\C-x\C-g" '(lambda ()
(interactive)
(save-buffer)
(comint-send-string "*moz-buffer*" "this.BrowserReload()\n"))))
Used in combination with http://hyperstruct.net/projects/mozlab
You can find my configuration (both in html & in tar'ed archive) on my site. It contains lot of settings for different modes
This block is the most important for me:
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
I've never been clear on the difference between those, though. Cargo cult, I guess...
I try to keep my .emacs organized. The configuration will always be a work in progress, but I'm starting to be satisfied with the overall structure.
All stuff is under ~/.elisp, a directory that is under version control (I use git, if that's of interest). ~/.emacs simply points to ~/.elisp/dotemacs which itself just loads ~/.elisp/cfg/init. That file in turn imports various configuration files via require. This means that the configuration files need to behave like modes: they import stuff they depend on and they provide themselves at the end of the file, e.g. (provide 'my-ibuffer-cfg). I prefix all identifiers that are defined in my configuration with my-.
I organize the configuration in respect to modes/subjects/tasks, not by their technical implications, e.g. I don't have a separate config file in which all keybindings or faces are defined.
My init.el defines the following hook to make sure that Emacs recompiles configuration files whenever saved (compiled Elisp loads a lot faster but I don't want to do this step manually):
;; byte compile config file if changed
(add-hook 'after-save-hook
'(lambda ()
(when (string-match
(concat (expand-file-name "~/.elisp/cfg/") ".*\.el$")
buffer-file-name)
(byte-compile-file buffer-file-name))))
This is the directory structure for ~/.elisp:
~/.elisp/todo.org: Org-mode file in which I keep track of stuff that still needs to be done (+ wish list items).
~/.elisp/dotemacs: Symlink target for ~/.emacs, loads ~/.elisp/cfg/init.
~/.elisp/cfg: My own configuration files.
~/.elisp/modes: Modes that consist only of a single file.
~/.elisp/packages: Sophisticated modes with lisp, documentation and probably resource files.
I use GNU Emacs, that version does not have real support for packages. Therefore I organize them manually, usually like this:
~/.elisp/packages/foobar-0.1.3 is the root directory for the package. Subdirectory lisp holds all the lisp files and info is where the documentation goes. ~/.elisp/packages/foobar is a symlink that points to the currently used version of the package so that I don't need to change my configuration files when I update something. For some packages I keep an ~/.elisp/packages/foobar.installation file around in which I keep notes about the installation process. For performance reasons I compile all elisp files in newly installed packages, should this not be the case by default.
Here's a couple of my own stuff:
Inserts date in ISO 8601 format:
(defun insertdate ()
(interactive)
(insert (format-time-string "%Y-%m-%d")))
(global-set-key [(f5)] 'insertdate)
For C++ programmers, creates a class skeleton (class's name will be the same as the file name without extension):
(defun createclass ()
(interactive)
(setq classname (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
(insert
"/**
* " classname".h
*
* Author: Your Mom
* Modified: " (format-time-string "%Y-%m-%d") "
* Licence: GNU GPL
*/
#ifndef "(upcase classname)"
#define "(upcase classname)"
class " classname "
{
public:
"classname"();
~"classname"();
private:
};
#endif
"))
Automatically create closing parentheses:
(setq skeleton-pair t)
(setq skeleton-pair-on-word t)
(global-set-key (kbd "[") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "<") 'skeleton-pair-insert-maybe)
i use paredit for easy (e)lisp handling and ido-mode minibuffer completions.
It's hard to answer this question, because everyone uses Emacs for very different purposes.
Further more, a better practice may be to KISS your dotemacs. Since the Easy Customization Interface is widely supported amongst Emacs' modes, you should store all your customization in your custom-file (which may be a separate place in your dotemacs), and for the dotemacs, put in it only load path settings, package requires, hooks, and key bindings. Once you start using Emacs Starter Kit, a whole useful bunch of settings may removed from your dotemacs, too.
See EmacsWiki's DotEmacs category. It provides lots of links to pages addressing this question.
(put 'erase-buffer 'disabled nil)
(put 'downcase-region 'disabled nil)
(set-variable 'visible-bell t)
(set-variable 'tool-bar-mode nil)
(set-variable 'menu-bar-mode nil)
(setq load-path (cons (expand-file-name "/usr/share/doc/git-core/contrib/emacs") load-path))
(require 'vc-git)
(when (featurep 'vc-git) (add-to-list 'vc-handled-backends 'git))
(require 'git)
(autoload 'git-blame-mode "git-blame"
"Minor mode for incremental blame for Git." t)
I set up some handy shortcuts to web pages and searches using webjump
(require 'webjump)
(global-set-key [f2] 'webjump)
(setq webjump-sites
(append '(
("Reddit Search" .
[simple-query "www.reddit.com" "http://www.reddit.com/search?q=" ""])
("Google Image Search" .
[simple-query "images.google.com" "images.google.com/images?hl=en&q=" ""])
("Flickr Search" .
[simple-query "www.flickr.com" "flickr.com/search/?q=" ""])
("Astar algorithm" .
"http://www.heyes-jones.com/astar")
)
webjump-sample-sites))
Blog post about how this works here
http://justinsboringpage.blogspot.com/2009/02/search-reddit-flickr-and-google-from.html
Also I recommend these:
(setq visible-bell t) ; no beeping
(setq transient-mark-mode t) ; visually show region
(setq line-number-mode t) ; show line numbers
(setq global-font-lock-mode 1) ; everything should use fonts
(setq font-lock-maximum-decoration t)
Also I get rid of some of the superfluous gui stuff
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1)))
One line to amend the load path
One line to load my init library
One line to load my emacs init files
Of course, the "emacs init files" are quite numerous, one per specific thing, loaded in a deterministic order.
emacs-starter-kit as a base, then I've added.. vimpulse.el, whitespace.el, yasnippet, textmate.el and newsticker.el.
In my ~/.emacs.d/$USERNAME.el (dbr.el) file:
(add-to-list 'load-path (concat dotfiles-dir "/vendor/"))
;; Snippets
(add-to-list 'load-path "~/.emacs.d/vendor/yasnippet/")
(require 'yasnippet)
(yas/initialize)
(yas/load-directory "~/.emacs.d/vendor/yasnippet/snippets")
;; TextMate module
(require 'textmate)
(textmate-mode 'on)
;; Whitespace module
(require 'whitespace)
(add-hook 'ruby-mode-hook 'whitespace-mode)
(add-hook 'python-mode-hook 'whitespace-mode)
;; Misc
(flyspell-mode 'on)
(setq viper-mode t)
(require 'viper)
(require 'vimpulse)
;; IM
(eval-after-load 'rcirc '(require 'rcirc-color))
(setq rcirc-default-nick "_dbr")
(setq rcirc-default-user-name "_dbr")
(setq rcirc-default-user-full-name "_dbr")
(require 'jabber)
;;; Google Talk account
(custom-set-variables
'(jabber-connection-type (quote ssl))
'(jabber-network-server "talk.google.com")
'(jabber-port 5223)
'(jabber-server "mysite.tld")
'(jabber-username "myusername"))
;; Theme
(color-theme-zenburn)
;; Key bindings
(global-set-key (kbd "M-z") 'undo)
(global-set-key (kbd "M-s") 'save-buffer)
(global-set-key (kbd "M-S-z") 'redo)
Always save my config in svn http://my-trac.assembla.com/ez-conf/browser/emacs.d
After reading this, I figured it would be good to have a simple site just for the best .emacs modifications. Feel free to post and vote on them here:
http://dotemacs.slinkset.com/
https://b7j0c.org/stuff/dotemacs.html
I'm new to emacs, in my .emacs file there are
indentation configuration
color theme
php mode, coffee mode and js2 mode
ido mode
FWIW, my .emacs is here:
http://svn.red-bean.com/repos/kfogel/trunk/.emacs
lots of stuff: https://github.com/tavisrudd/emacs.d
el-get has made managing it and dependencies a lot easier: https://github.com/tavisrudd/emacs.d/blob/master/dss-init-el-get.el
For Scala coders
;; Load the ensime lisp code... http://github.com/aemoncannon/ensime
(add-to-list 'load-path "ENSIME_ROOT/elisp/")
(require 'ensime)
;; This step causes the ensime-mode to be started whenever ;; scala-mode is started for a buffer. You may have to customize this step ;; if you're not using the standard scala mode.
(add-hook 'scala-mode-hook 'ensime-scala-mode-hook)
;; MINI HOWTO: ;; Open .scala file. M-x ensime (once per project)
My emacs configuration has grown up pretty big over the years and I have lot of useful stuff for me there but if I have two functions it probably would have been those ones.
Define C-x UP and C-x DOWN to move the current line or down keeping the cursor at the right place :
;Down/UP the current line
(global-set-key '[(control x) (up)] 'my-up-line)
(global-set-key '[(control x) (down)] 'my-down-line)
(defun my-down-line()
(interactive)
(let ((col (current-column)))
(forward-line 1)
(transpose-lines 1)
(forward-line -1)
(forward-char col)
)
)
(defun my-up-line()
(interactive)
(let ((col (current-column)))
(transpose-lines 1)
(forward-line -2)
(forward-char col)
)
)