I recently ran into some trouble with cron and crontab because the text editor I use, emacs, inserts several spaces instead of a tab, when I press the tab key. This issue persists throughout all the major modes, regardless of the tab width set for each mode.
How can emacs be forced to use the tab character instead of tabs composed of multiple spaces?
If you want to insert a TAB character, then use C-q TAB. The TAB key is used for a different purpose (mostly to indent/align text/code according to various rules, tho it's also used for various other purposes such as performing completion, skipping from one field to another, etc...).
Set the variable indent-tabs-mode. You can do that by customizing the variable with M-x customize-variable, on the fly with M-x set-variable, or in Elisp with the setq function.
Related
I have a text that I already typed in a text editor, but when I open it in Emacs, so I can keep working o Emacs (Org-Mode), it appears it is not wrapping the lines propperly. The paragraph (or what it is supposed to be a paragraph) appears in a single line, instead of having a line break when reaching the screen limit.
Do you guys know how to reformat these line breaks?
Emacs has a built-in variable called word-wrap, which has a default value of nil. When word-wrap is nil, long lines are wrapped indiscriminately at the window-edge without consideration as to whether a whole word is visually broken up -- i.e., part of a word may be at the end of the visually wrapped line and part of the word may be at the beginning of the subsequent visually wrapped line.
The most common method of enabling word-wrap is to use the built-in visual-line-mode: http://www.gnu.org/software/emacs/manual/html_node/emacs/Visual-Line-Mode.html Visual line mode includes a few other goodies, like remapping certain keyboard shortcuts and pretty bitmap images in the fringes if they are visible in the window. Enabling visual-line-mode can be accomplished a number of ways -- one example is manually: M-x visual-line-mode
As we know, mode is very important in emacs. But I feel I am not very clear about how to set it. For example, I often see something like (***-mode 1) or (***-mode) in .emacs file. And some tutorials also say that a mode can be set by M-x ***-mode. Could you tell me what's the differences between them and how to use them? Thanks!
A Lisp function is a piece of code which declares a name for another piece of code to be executed later.
(defun hello ()
(message "Hiya!"))
Now, you can invoke the named code from anywhere else in Lisp.
(hello)
Only at this point does the message form get executed.
Many Lisp functions contain an interactive form which specifies how they should behave when called interactively (for example, should it prompt for an argument, or use the cursor or mouse position as the argument, etc). Those which do can be invoked with M-x and the function name.
A major mode specifies a function which sets up some variables to exclusively control the behavior of Emacs. For example, M-x text-mode sets a (very basic) regime for word wrapping and cursor movement which is suitable for text files. When you are in text mode, you cannot be in C++ mode, or Lisp mode, or fundamental mode. These are other major modes which define different or additional functionality suitable for editing other types of text.
Because a major mode is exclusive, it is usually a function which doesn't take any arguments. So to put the current buffer in text mode, the Lisp code is simply
(text-mode)
Minor modes, by contrast, specify additional behavior which is independent from the major mode. For example, Overwrite mode specifies a different behavior when inserting text before some other text -- normally, Emacs pushes any existing text ahead, but when overwrite mode is active, existing text in front of the cursor will be replaced as you type.
You can have multiple minor modes active at any time -- you could have flyspell (spell checking as you type), tool bar mode, menu bar mode, and line number mode active at the same time as you are in text mode and overwrite mode.
Because of this, a common (though not universal) convention for minor modes is to perform a toggle. When you are already in toolbar mode, M-x toolbar-mode will disable this minor mode. To unambiguously disable the mode, pass it a negative numeric argument;
(toolbar-mode -1)
Without the argument, the code will toggle -- the result will depend on whether the mode was already active, or not.
(As noted in a comment, this changed in Emacs 24; I'm describing the historical behavior.)
I recently ran into some trouble with cron and crontab because the text editor I use, emacs, inserts several spaces instead of a tab, when I press the tab key. This issue persists throughout all the major modes, regardless of the tab width set for each mode.
How can emacs be forced to use the tab character instead of tabs composed of multiple spaces?
If you want to insert a TAB character, then use C-q TAB. The TAB key is used for a different purpose (mostly to indent/align text/code according to various rules, tho it's also used for various other purposes such as performing completion, skipping from one field to another, etc...).
Set the variable indent-tabs-mode. You can do that by customizing the variable with M-x customize-variable, on the fly with M-x set-variable, or in Elisp with the setq function.
I'm a beginner with emacs. Altough I'm finding it amusing and challenging, I still don't know some basic things, like, when I open a text or a piece of script wrote in another editors, emacs don't show the text formatted properly (missing all tabs, all text left-aligned) and vice-versa.
Also, when I copy a link with emacs with M-w, my clipboard is still empty and I can't paste it in a browser. I already did my "homework". I've read the tutorial and I'm almost finishing the manual and didn't see anything to address that.
tnx in advance.
Some editors, like Intellij IDEA for example, will indent code based on how they understand it and not based on how it was actually indented, there's no Emacs mode that operates in the same way, not to my best knowledge. If you were using something like Eclipse or MS Visual Studio before - then you probably just have a different size of tab character (this is why some programmers insist on indenting code with spaces rather than tabs). But the width of the tab character is adjustable. In order to customize it you would:
add in your initialization file (usually .emacs file in your $HOME directory, you can create one, if it is not there yet):
;; makes tab character as wide as four space characters
(setq default-tab-width 4)
though some other major editing modes override this variable, you would need to tell what language you are dealing with to get better instructions.
Clipboard, see this answer: How to copy text from Emacs to another application on Linux if you are on Linux, then likely you need to set x-select-enable-clipboard to t.
Aligning text to the right (or left for LTR languages) is not possible in Emacs, as far as I understand. You could align block of text, if you split it into lines and align on the line ends, but that would mean aligning by adding spaces at the beginning - something you don't really want to do.
Tabs should work (you might need to fix the width). Use mouse to select to the clipboard, or use CtrlInsert to copy and ShiftDelete to cut.
Assuming emacs has picked the right mode for the file - it usually does - you can press C-x h to select all, then TAB to indent all selected lines. What other editors are you using, and what platform(s)?
As for the clipboard issue, some builds of emacs work correctly with the native clipboard, some don't. You might want to investigate CUA mode.
Is there an Emacs minor-mode (or piece of elisp code) that lets you selectively hide/show environments while in LaTeX mode? For instance, I would like to move to the beginning of a long \begin{figure} block, hit a keystroke, and have the contents of that figure environment hidden from view. Similarly with \begin{proof} and so on, and ideally even with \subsections.
Is this possible? I just tried hs-minor-mode, allout-mode, and outline-minor-mode, but most of them don't recognize LaTeX's environments, e.g. hs-minor-mode fails with "scan error: unbalanced parentheses". I would prefer not to have to enter explicit folding marks like {{{ as in folding-mode.
[Ideally it would be great if the folding were persistent, but I see that that question doesn't have an accepted answer yet.]
AUCTeX does folding: http://www.gnu.org/software/auctex/manual/auctex.html#Folding
A popular complaint about markup languages like TeX and LaTeX is that there is too much clutter in the source text and that one cannot focus well on the content. There are macros where you are only interested in the content they are enclosing, like font specifiers where the content might already be fontified in a special way by font locking. Or macros the content of which you only want to see when actually editing it, like footnotes or citations. Similarly you might find certain environments or comments distracting when trying to concentrate on the body of your document.
With AUCTeX’s folding functionality you can collapse those items and replace them by a fixed string, the content of one of their arguments, or a mixture of both. If you want to make the original text visible again in order to view or edit it, move point sideways onto the placeholder (also called display string) or left-click with the mouse pointer on it. (The latter is currently only supported on Emacs.) The macro or environment will unfold automatically, stay open as long as point is inside of it and collapse again once you move point out of it. (Note that folding of environments currently does not work in every AUCTeX mode.)
In order to use this feature, you have to activate TeX-fold-mode which will activate the auto-reveal feature and the necessary commands to hide and show macros and environments. You can activate the mode in a certain buffer by typing the command M-x TeX-fold-mode RET or using the keyboard shortcut C-c C-o C-f. If you want to use it every time you edit a LaTeX document, add it to a hook:
(add-hook 'LaTeX-mode-hook (lambda ()
(TeX-fold-mode 1)))
If it should be activated in all AUCTeX modes, use TeX-mode-hook instead of LaTeX-mode-hook.
Once the mode is active there are several commands available to hide and show macros, environments and comments...