Domanda

Di recente ho cambiato computer, e da qualche parte lungo la strada ho perso il mio .emacs. Sto provando a ricostruirlo di nuovo, ma mentre ci sono, ho pensato di prendere altre buone configurazioni che altre persone usano.

Quindi, se usi Emacs, cosa c'è in tuo .emacs?

Il mio è piuttosto sterile in questo momento, contenente solo:

  1. Modalità blocco caratteri globale! (global-font-lock-mode 1)
  2. Le mie preferenze personali rispetto a rientri, tabulazioni e spazi.
  3. Usa cperl-mode invece di perl-mode.
  4. Una scorciatoia per la compilazione.

Cosa ritieni utile?

È stato utile?

Soluzione

Utilizza il sito definitivo dotfiles . Aggiungi qui i tuoi ".emacs". Leggi i ".emacs" di altri.

Altri suggerimenti

Il mio frammento preferito. Il massimo del piacere per gli occhi di Emacs:

;; 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)

Quindi, quando si modifica lisp / schema, si vede ad esempio quanto segue:

(global-set-key "^Cr" '(λ () (interactive) (revert-buffer t t nil)))

Ho questo per cambiare yes o no prompt in y o n prompt:

(fset 'yes-or-no-p 'y-or-n-p)

Ho questi per avviare Emacs senza tanto " fanfare " che ho ricevuto da questa domanda .

(setq inhibit-startup-echo-area-message t)
(setq inhibit-startup-message t)

E la funzione di Steve Yegge per rinominare un file che " rielaborazione insieme al relativo 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))))))

Una cosa che può rivelarsi molto utile: prima che diventi troppo grande, prova a dividerlo in più file per varie attività: il mio .emacs imposta semplicemente il mio percorso di caricamento e carica un mucchio di file - ho tutto le mie impostazioni specifiche della modalità in mode-configs.el, le combinazioni di tasti in keys.el, eccetera

Il mio .emacs ha solo 127 righe, ecco i piccoli frammenti più utili:

;; keep backup files neatly out of the way in .~/
(setq backup-directory-alist '(("." . ".~")))

Questo fa sì che i file * ~ che trovo ingombra la directory vadano in una directory speciale, in questo caso. ~

;; 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

Questo imposta uniquify che cambia quei file brutti < 2 > ecc. nomi di buffer che ottieni quando più file hanno lo stesso nome in un nome univoco molto più ordinato usando tutto il percorso del file come deve.

Questo è tutto ... il resto è roba abbastanza standard che sono sicuro che tutti conoscono.

Questo non è l'intero kit e kaboodle, ma è alcuni degli snippet più utili che ho raccolto:

(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)))

Ne ho molti altri che sono già stati menzionati, ma questi sono assolutamente necessari secondo me:

(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

Puoi guardare qui: http://www.dotemacs.de/

E il mio .emacs è piuttosto lungo anche per metterlo qui, quindi la risposta non sarà troppo leggibile. Ad ogni modo, se lo desideri, posso inviarlo a te.

Inoltre, ti consiglio di leggere questo: http: // steve. yegge.googlepages.com/my-dot-emacs-file

Ecco alcune mappature chiave da cui sono diventato dipendente:

(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)

Altre cose varie, principalmente per lo sviluppo di C ++:

;; 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))

Per aggiornare la pagina Web che stai modificando da 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"))))

Utilizzato in combinazione con http://hyperstruct.net/projects/mozlab

Puoi trovare la mia configurazione (sia in html & amp; in archivio tar'ed) su il mio sito . Contiene molte impostazioni per diverse modalità

Questo blocco è il più importante per 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)

Non sono mai stato chiaro sulla differenza tra questi, però. Culto del carico, immagino ...

Cerco di mantenere organizzati i miei .emacs. La configurazione sarà sempre in fase di elaborazione, ma sto iniziando a essere soddisfatto della struttura generale.

Tutte le cose sono in ~/.elisp, una directory che è sotto controllo di versione (io uso git, se questo è di interesse). ~/.emacs indica semplicemente ~/.elisp/dotemacs che a sua volta carica ~/.elisp/cfg/init. Tale file a sua volta importa vari file di configurazione tramite require. Ciò significa che i file di configurazione devono comportarsi come modalità: importano cose da cui dipendono e si provide alla fine del file, ad es. (provide 'my-ibuffer-cfg). Prefisso tutti gli identificatori che sono definiti nella mia configurazione con my-.

Organizzo la configurazione in relazione a modalità / soggetti / compiti, non in base alle loro implicazioni tecniche, ad es. I non ho un file di configurazione separato in cui sono definiti tutti le combinazioni di tasti o le facce.

Il mio init.el definisce il seguente hook per assicurarsi che Emacs ricompili i file di configurazione ogni volta che vengono salvati (Elisp compilato si carica molto più velocemente ma non voglio fare questo passo manualmente):

;; 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))))

Questa è la struttura delle directory per ~/.elisp/todo.org:

~/.elisp/cfg: file in modalità Org in cui tengo traccia delle cose che devono ancora essere fatte (+ voci della lista dei desideri).

~/.elisp/modes: destinazione Symlink per ~/.elisp/packages, carica ~/.elisp/packages/foobar-0.1.3.

lisp: i miei file di configurazione.

info: modalità costituite solo da un singolo file.

~/.elisp/packages/foobar: modalità sofisticate con lisp, documentazione e probabilmente file di risorse.

Uso GNU Emacs, quella versione non ha un vero supporto per i pacchetti. Pertanto li organizzo manualmente, di solito in questo modo: ~/.elisp/packages/foobar.installation è la directory principale per il pacchetto. La sottodirectory <=> contiene tutti i file lisp e <=> è dove va la documentazione. <=> è un collegamento simbolico che punta alla versione attualmente utilizzata del pacchetto, quindi non ho bisogno di cambiare i miei file di configurazione quando aggiorno qualcosa. Per alcuni pacchetti ho un file <=> in cui tengo appunti sul processo di installazione. Per motivi di prestazioni, compilo tutti i file elisp nei pacchetti appena installati, nel caso in cui ciò non avvenga per impostazione predefinita.

Ecco un paio di cose mie:

Inserisce la data nel formato ISO 8601:

(defun insertdate ()
  (interactive)
  (insert (format-time-string "%Y-%m-%d")))

(global-set-key [(f5)] 'insertdate)

Per i programmatori C ++, crea uno scheletro di classe (il nome della classe sarà lo stesso del nome del file senza estensione):

(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
"))

Crea automaticamente parentesi di chiusura:

(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)

Uso paredit per una facile gestione (e) lisp e completamenti del minibuffer in modalità ido.

È difficile rispondere a questa domanda, perché tutti usano Emacs per scopi molto diversi.

Inoltre, una migliore pratica potrebbe essere quella di BACIARE i tuoi dotemacs. Dato che Easy Customization Interface è ampiamente supportato tra le modalità di Emacs, dovresti memorizzare tutta la tua personalizzazione nel tuo custom-file (che potrebbe essere un posto separato nei tuoi dotemacs) e per dotemacs , inserisci solo le impostazioni del percorso di caricamento, il pacchetto richiede, ganci e combinazioni di tasti. Dopo aver iniziato a utilizzare Emacs Starter Kit , un utile un sacco di impostazioni potrebbe essere rimosso anche dai tuoi dotemacs.

Vedi la DotEmacs di EmacsWiki. Fornisce molti collegamenti a pagine che affrontano questa domanda.

(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)

Ho impostato alcune scorciatoie utili per pagine Web e ricerche usando 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))

Post di blog su come funziona qui

http: //justinsboringpage.blogspot .com / 2009/02 / search-reddit-flickr-e-google-from.html

Inoltre raccomando questi:

(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)

Inoltre mi sbarazzo di alcune delle cose superflue della gui

  (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)))

Una riga per modificare il percorso di caricamento Una riga per caricare la mia libreria init Una riga per caricare i miei file init di emacs

Ovviamente, " emacs init files " sono piuttosto numerosi, uno per cosa specifica, caricati in un ordine deterministico.

emacs-starter-kit come base, quindi I hai aggiunto .. vimpulse.el, whitespace.el, yasnippet, textmate.el e newsticker.el.

Nel mio file ~ / .emacs.d / $ USERNAME.el (dbr.el):

(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)

Salva sempre la mia configurazione in svn http: // my-trac .assembla.com / ez-conf / browser / emacs.d

Dopo aver letto questo, ho pensato che sarebbe bello avere un sito semplice solo per le migliori modifiche .emacs. Sentiti libero di postare e votare su di loro qui:

http://dotemacs.slinkset.com/

Sono nuovo di emacs, nel mio file .emacs ci sono

  • configurazione del rientro
  • tema colore
  • modalità php, modalità caffè e modalità js2
  • modalità ido

Per Scala programmatori

;; 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)

La mia configurazione di emacs è cresciuta abbastanza grande nel corso degli anni e ho molte cose utili per me lì, ma se avessi due funzioni sarebbe probabilmente quelle.

Definisci C-x SU e C-x GIÙ per spostare la linea corrente o verso il basso mantenendo il cursore nella posizione corretta:

;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)
    )
  )
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top