Domanda

Come posso fare in modo che Emacs mostri spazi vuoti (come uno spazio, una scheda, un salto di linea, ecc.). Molti altri editor come Kate ed Eclipse hanno questa funzione e trovo molto utile vedere quando il codice è indentato a causa del mix di spazi e tab (in particolare Python).

È stato utile?

Soluzione

WhiteSpace è una modalità minore di Emacs per visualizzare tutti i caratteri degli spazi bianchi nel buffer corrente .

Ecco uno screenshot di WhiteSpace in azione preso direttamente dal wiki di Emacs,

 modalità spazi bianchi in azione

Nota: WhiteSpaceMode ora ha sostituito BlankMode

Altri suggerimenti

Tutte le possibili impostazioni da fare che sembrano essere riassunte qui (modalità vuota) e qui e qui (ShowWhiteSpace)

anche:

(if (>= emacs-major-version 22)
  (progn
    ;; Mode to use with Emacs 22
    ;; http://emacswiki.org/cgi-bin/wiki/BlankMode
    (require 'blank-mode)
    ;; Mode not active by default: let's activate it
    (global-blank-mode t)
    ;; ... activate it when text mode where color syntax is not active by default
    (add-hook 'text-mode-hook 'blank-mode-on)
    ;; All invisible chars are shown, except newline char.
    (setq blank-chars '(tabs spaces trailing lines space-before-tab))
    ;; Show only for one color, no mark inserted
    (setq blank-style '(color))
    ;; Use for normal space (not shown)
    (set-face-background 'blank-space-face nil)
    (set-face-foreground 'blank-space-face "black")
    ;; used for non breakable space
    (set-face-background 'blank-hspace-face "PaleGreen")
    (set-face-foreground 'blank-hspace-face "black")
    ;; Used for spaces left of a tab
    (set-face-background 'blank-space-before-tab-face "orange")
    (set-face-foreground 'blank-space-before-tab-face "black")
    ;; Used for tab
    (set-face-background 'blank-tab-face "lemonchiffon")
    (set-face-foreground 'blank-tab-face "black")
    ;; used for extra space at the end of a line
    (set-face-background 'blank-trailing-face "gold")
    (set-face-foreground 'blank-trailing-face "black")
    ;; Used for line too long
    (set-face-background 'blank-line-face "snow2")
    (set-face-foreground 'blank-line-face "black")
  )
  (progn
    ;; For older Emacs prior to version 22.
    ;; http://www.emacswiki.org/cgi-bin/wiki/show-wspace.el
    (require 'show-wspace)
    (add-hook 'font-lock-mode-hook 'show-ws-highlight-tabs)
    (add-hook 'font-lock-mode-hook 'show-ws-highlight-hard-spaces)
    (add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)
  )
)

trattino-rotto? - non usare mai le schede nel tuo codice - lo spazio su disco è poco costoso in questi giorni.

Inserisci (setq-default indent-tabs-mode nil) nel tuo file .emacs. Abituarsi a digitare C-x h M-x untabify per annullare l'assemblaggio dell'intero buffer. Per cercare le schede digitare C-s C-i . Se hai dei caratteri di controllo oscuri nei tuoi buffer, puoi vederli con M-x hexl-mode .

Anche C-x h M-x indent-region indenterà l'intero buffer. Alcune modalità come vhdl-mode hanno un comando beautify region.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top