Come posso ottenere emacs per cambiare scheda per spostare il testo selezionato a sinistra di 4 spazi?Emacs Shift-Tab a sinistra sposta il blocco
risposta
Rimuove 4 spazi dalla parte anteriore della riga corrente (purché gli spazi esistano).
(global-set-key (kbd "<S-tab>") 'un-indent-by-removing-4-spaces)
(defun un-indent-by-removing-4-spaces()
"remove 4 spaces from beginning of of line"
(interactive)
(save-excursion
(save-match-data
(beginning-of-line)
;; get rid of tabs at beginning of line
(when (looking-at "^\\s-+")
(untabify (match-beginning 0) (match-end 0)))
(when (looking-at "^ ")
(replace-match "")))))
Se la variabile tab-width
capita di essere 4 (e questo è ciò che si vuole "annullare"), allora si può sostituire il (looking-at "^ ")
con qualcosa di più generale come (concat "^" (make-string tab-width ?\))
.
Inoltre, il codice convertirà le schede nella parte anteriore della linea in spazi utilizzando untabify.
Per fare ciò, utilizzo il comando indent-rigidly
, associato a C-x TAB
. Dargli l'argomento -4 per spostare la regione selezionata a sinistra di quattro spazi: C-u -4 C-x TAB
.
http://www.gnu.org/s/emacs/manual/html_node/elisp/Region-Indent.html
Per la stessa voce di manuale, potresti preferire 'indent-code-rigidly 'dato che lascia solo commenti e stringhe multi-linea – toolbear
ho fatto alcune funzioni per la tabulazione una regione su quattro spazi a destra oa sinistra a seconda se scheda o MAIUSC + TAB si utilizza:
(defun indent-region-custom(numSpaces)
(progn
; default to start and end of current line
(setq regionStart (line-beginning-position))
(setq regionEnd (line-end-position))
; if there's a selection, use that instead of the current line
(when (use-region-p)
(setq regionStart (region-beginning))
(setq regionEnd (region-end))
)
(save-excursion ; restore the position afterwards
(goto-char regionStart) ; go to the start of region
(setq start (line-beginning-position)) ; save the start of the line
(goto-char regionEnd) ; go to the end of region
(setq end (line-end-position)) ; save the end of the line
(indent-rigidly start end numSpaces) ; indent between start and end
(setq deactivate-mark nil) ; restore the selected region
)
)
)
(defun untab-region (N)
(interactive "p")
(indent-region-custom -4)
)
(defun tab-region (N)
(interactive "p")
(if (active-minibuffer-window)
(minibuffer-complete) ; tab is pressed in minibuffer window -> do completion
; else
(if (string= (buffer-name) "*shell*")
(comint-dynamic-complete) ; in a shell, use tab completion
; else
(if (use-region-p) ; tab is pressed is any other buffer -> execute with space insertion
(indent-region-custom 4) ; region was selected, call indent-region
(insert " ") ; else insert four spaces as expected
)))
)
(global-set-key (kbd "<backtab>") 'untab-region)
(global-set-key (kbd "<tab>") 'tab-region)
Edit: il codice di Aggiunto Maven per controllare se in minibuffer, nonché per il completamento scheda in buffer specifici (shell, ad esempio).
Nice, la risposta accettata funzionava solo per 1 riga, non per le regioni –
Perfetto. Funziona per regioni e linee. Replica le funzionalità di altri editor comuni. – mythicalcoder
Ho migliorato la risposta di Stanley Bak. Per me, questa associazione a chiave globale stava rovinando il completamento del minibuffer.
Quindi ho incluso anche una custodia per il minibuffer.
Modifica: Rinomina indent-region
->indent-region-custom
.
indent-region
si scontrano con il comando esistente e restituisce un errore per il rientro su salvataggio (gancio per il salvataggio precedente) e alcune altre combinazioni di tasti.
(defun indent-region-custom(numSpaces)
(progn
;; default to start and end of current line
(setq regionStart (line-beginning-position))
(setq regionEnd (line-end-position))
;; if there's a selection, use that instead of the current line
(when (use-region-p)
(setq regionStart (region-beginning))
(setq regionEnd (region-end))
)
(save-excursion ; restore the position afterwards
(goto-char regionStart) ; go to the start of region
(setq start (line-beginning-position)) ; save the start of the line
(goto-char regionEnd) ; go to the end of region
(setq end (line-end-position)) ; save the end of the line
(indent-rigidly start end numSpaces) ; indent between start and end
(setq deactivate-mark nil) ; restore the selected region
)
)
)
(defun untab-region (N)
(interactive "p")
(indent-region-custom -4)
)
(defun tab-region (N)
(interactive "p")
(if (active-minibuffer-window)
(minibuffer-complete) ; tab is pressed in minibuffer window -> do completion
(if (use-region-p) ; tab is pressed is any other buffer -> execute with space insertion
(indent-region-custom 4) ; region was selected, call indent-region-custom
(insert " ") ; else insert four spaces as expected
)
)
)
(global-set-key (kbd "<backtab>") 'untab-region)
(global-set-key (kbd "<tab>") 'tab-region)
- 1. Inserisci elemento in linea e animazione sposta a sinistra
- 2. Android AlertDialog Sposta PositiveButton a destra e NegativeButton a sinistra
- 3. Scorciatoia da tastiera per "untab" (sposta un blocco di codice a sinistra) in eclipse/aptana?
- 4. Sposta menu a discesa materiale angolare a sinistra
- 5. Blocco di equazioni di allineamento a sinistra
- 6. L'immagine di sfondo si sposta da sinistra a destra
- 7. jquery sposta la diapositiva da sinistra a destra e indietro
- 8. Intellij: Sposta la scheda a sinistra ea destra
- 9. NSTextField sizeToFit o aggiornamento del frame sposta il testo a sinistra
- 10. Commento blocco C indent in Emacs
- 11. Emacs sposta le finestre divise in una direzione specificata?
- 12. Emacs cperl - rientro nel blocco costante
- 13. Perché lasciando modalità di inserimento si sposta la posizione del cursore a sinistra
- 14. si sposta verso sinistra quando si ruota l'iPad da orizzontale a verticale
- 15. Eclipse Keystroke per far scorrere il blocco di testo a sinistra/destra
- 16. UIImageView come callout leftCalloutAccessoryView sposta automaticamente l'angolo in alto a sinistra
- 17. Perché StackPanel non inserisce il blocco di testo a sinistra e il pulsante a destra in Silverlight?
- 18. Sposta ramo corrente a Gerrit
- 19. jScrollPane: la barra di scorrimento orizzontale si sposta a sinistra durante il trascinamento del bit jspDrag in Webkit
- 20. Overflow GCC a sinistra
- 21. Come si sposta il puntatore su o giù più righe con Emacs?
- 22. Come spostare il testo selezionato a sinistra o a destra
- 23. MeasureString() applica il testo a sinistra e a destra.
- 24. Sposta il costruttore sull'oggetto derivato
- 25. ridimensionamento di un UIScrollView con il blocco di animazioni si sposta origine
- 26. UITextView sposta il testo in modo diverso rispetto a UILabel
- 27. Come aggiornare altri puntatori quando realloc sposta il blocco di memoria?
- 28. Come posso centrare il testo allineato a sinistra anche quando si esegue il wrapping?
- 29. Display Destra a sinistra errato
- 30. destra a sinistra Bar in
Bello! Ma userei QUANDO invece di IF, poiché non c'è altra clausola. – Ken
per me, non funziona con una regione selezionata. Solo con la prima riga: -/ – Ismael
Per me, non funziona affatto. :( –