How to enforce 80 columns in latex using emacs - emacs

I see that fill column shows a nice bar at the point that I want.
This is great.
But I'm lazy. I would like it to automatically hit return for me. Not to mention that sometimes I go back to edit stuff and my 80 columns rule gets everything messy.
Is this possible?

Turn on auto-fill-mode:
(setf fill-column 80)
(add-hook 'latex-mode-hook #'auto-fill-mode)
When Auto Fill mode is enabled, inserting a space at a column
beyond `current-fill-column' automatically breaks the line at a
previous space.
If you go back to edit code later, simply M-q (fill-paragraph) to rewrap.

Related

Why does emacs display tabs differently?

So I've heard about the goodness of emacs and have only recently started using it. Forgive me if this is a stupid question, but why does emacs display tabs, differently? It seems as though it doubles the number of spaces, but it doesn't, at least, I guess. Here're some pictures to describe what I'm talking about:
And this is what it looks like in emacs:
As I've previously stated, it seems as though it doubles the number of spaces. When I add this line to .emacs:
(setq c-basic-offset 4)
and reindenting the code using C-x h C-M-\ makes it look normal in emacs, but the secondary indentation are in-line with the first indentation (as in 2 tabs are now 1 tab) when viewed in other text editors, and again, I couldn't understand why. Changing it to
(setq c-basic-offset 8)
makes it save and display normally in other text editors though. At this point I'm really, really confused.
Can someone please explain why? Thanks.
The variable tab-width is the distance between tab spaces in columns, and defaults to 8. If you'd like it to default to 4, you can (setq-default tab-width 4). If you'd like to untabify everything and convert tabs to spaces, you can do M-: (untabify (point-min) (point-max)).
And you might find this thread helpful, especially the point on tab-stop-list when you want to ADD your own tabs.
You can also adopt sanity and not use TAB chars in your code. ;-)
To prevent inserting TAB chars when you hit the TAB key (and RET or C-j, depending on your Emacs version) set the value of option indent-tabs-mode to nil.
To remove pre-existing TAB chars from code you are editing, use command untabify.
See also Tabs Are Evil and Untabify Upon Save.
And note that, in Emacs, whether or not you use TAB chars is unrelated to how much and whether code is indented. For example, option c-basic-offset governs indentation amount regardless of whether TABs are used for some of the indenting.
Note too that after you kick the TAB habit, any TAB chars left in your code that are meaningful to the code are much easier to find. They are not lost in an ocean of insignificant-whitespace TABs.
Finally, note that there are various ways to highlight TAB chars. Command hc-toggle-highlight-tabs in library highlight-chars.el is one way. See Show Whitespace.

emacs: ruby mode after reindent-then-newline-and-indent

i am using emacs 23.2 and reference configurations from purcell https://github.com/purcell/emacs.d
i met a problem when i am edit ruby file and rails file, see below
steps:
1. move the cursor to somewhere
2. hit "RET" key to add more new line, then move the cursor to somewhere
3. the red space happened at the last new line.
do you know how to turn this mark off?
What's your problem with this feature? The red space goes away as soon as you
start typing doesn't it?
The feature is show-trailing-whitespace, and it's meant to help you see
spurious space at EOL. Which is very helpful for team development
environment, as checking in such code will annoy your teammates.
What you should do is add a before-save-hook that removes spurious
whitespace see:
http://www.emacswiki.org/emacs/DeletingWhitespace#toc3
code:
(add-hook 'before-save-hook 'delete-trailing-whitespace)
If you want to disable show-trailing-whitespace as well:
(add-hook 'ruby-mode-hook (lambda ()
(setq show-trailing-whitespace nil)))
You might like to look at the ws-trim.el library, which removes trailing whitespace from lines which you edit, but by default does not remove them from other lines*.
I find this best for version-control (compared to deleting all trailing whitespace upon saving), as you do not introduce changes in other people's work if you edit the same file.
(*) although it is also nicely configurable if you want it to do more than that.

Is there a good emacs mode for displaying and editing huge delimiter separated files?

I've been searching without finding for a while for a mode that makes editing huge tab/comma/colon-separated files easy. I've been wanting a mode that ensures that columns always line up, just like org-mode tables. I know I can easily turn the whole file into an org-mode table and then turn it back when I'm done, but that gets really slow with huge files, and is a hassle for quick edits (there's also the problem of what happens if a field contains a vertical bar). So does anyone know of either a mode or a built-in function/variable I can use so that I can get a file like
col1\tcol2\tcol3
very long column1\tcol2\tcol3
displayed like
col1 col2 col3
very long column1 col2 col3
? (perhaps with some color lining the separator)
Perhaps you could tell us what you've already found and rejected?
If you've been searching, then you must surely have seen http://emacswiki.org/emacs/CsvMode ? You don't mention it, or say why it wasn't any good, though.
SES (Simple Emacs Spreadsheet) might be a useful approach:
C-hig (ses) RET
You can create a ses-mode buffer and yank tab-delimited data into it (that's the import mechanism).
It's probably more hassle than you were after, though, and I'm not sure how well it will perform with "huge" files.
Try csv-mode, which works in at least Emacs 24.
You can set the variable csv-separators to change the separator if you do not use the default one (comma).
See EmacsWiki.
As #choroba mentioned, use csv-mode. To answer your question specifically:
Make sure your separator is in csv-separators, which for example you can set with
(setq csv-separators '("," " "))
Use csv-align-fields (default keybinding C-c C-a) to line up the field values into columns.
#unhammer's comment about aligning only visible lines is great. Their code properly indented:
(add-hook 'csv-mode-hook
(lambda ()
(define-key csv-mode-map (kbd "C-c C-M-a")
(defun csv-align-visible (&optional arg)
"Align visible fields"
(interactive "P")
(csv-align-fields nil (window-start) (window-end))
)
)
)
)
There is pretty-column.el, which I found in Group gnu.emacs.sources years ago (it was added in 1999). That group is now blocked, by Google. I just used pretty-column.el on a ~5000 line tab-separated text file that Org mode choked on (Org mode has a 999 line limit on converting such a file--for that reason).
Added in edit: This seems to now be called delim-col.el (see this Emacs Wiki entry); the author is the same person.

Emacs word wrap at a specific column number

I like to run my editor full-screen. The only thing is, though, that when I do this, the word wrap only kicks in when the line hits the right edge of the screen. I would like it to do so, already when the line hits, say, column number 200.
How do I do that?
I would like it to happen in all modes, e.g., Org-mode. I added the line (global-visual-line-mode t) to my .emacs file, in order for the word wrapping also to work in org-mode.
I'm running Emacs 23.
I got it working! Here is what I added to my .emacs file to make it happen:
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook
'(lambda() (set-fill-column 80)))
Type M-x auto-fill-mode to activate automatic line-wrapping after a certain column. Then set the actual line width through the variable fill-column as described by user choroba (C-x f).
Note though that this works a bit differently from what other text editors do. M-q will re-format the current paragraph.
You can set the line width with C-xf (set-fill-column).
Afterwards, you might need to hit M-q to reformat the current paragraph (fill-paragraph), or select text to be justified and run fill-region.
The suggestion for turn-on-auto-fill will work if you want hard newlines in the files you're editing. If not, and you just want word-wrap, consider instead visual-fill-column-mode, which just does the normal word-wrap that would happen at the edge of the window, but at the specified fill-column.
See the Emacs manual (C-h r), node Filling. See in particular the first subnode in the menu, Auto Fill.

Turn off Emacs Whitespace-mode "Long Line" Visualization

I personally keep all lines under 80 characters, but I also work on projects in teams where other programmers don't care about line length.
I love using whitespace-mode, but the long line visualization is really annoying when I'm working on projects where I shouldn't interfere with the long lines. It seems like it should be easy to turn off the long line visualization---I hit m-x global-whitespace-toggle-options l, and then can hit m-x global-whitespace-toggel-options ? to confirm that the "long-line visualization" is turned off. But long lines are still highlighted. I kill buffers and reload them, and highlighting is still there. I'm definitely using global, not local, whitespace-mode.
Why can't I turn off the long line visualization?
The last time I customized whitespace-mode, I noticed that my changes to the settings didn't have any effect in buffers that already existed; try recreating the buffer, or leaving and reentering whitespace-mode. In case you don't already know, you can use M-x customize-group whitespace to turn off that particular option entirely, rather than doing it manually.
Edit: Specifically you want to customize the whitespace-style variable. This lets you turn on and off individual styles. In this case you should turn off the ones labelled "(Face) Lines" and "(Face) Lines, only overlong part". The former changes the face of the whole line when it is overly long, while the latter only changes the face of the part that extends past the threshold.
(Other options in this group define the faces that whitespace-mode will use to highlight the styles you've turned on, the regexes it uses to identify certain situations, etc, but usually you only care about whitespace-style).
Set whitespace-line-column to a higher value (default is 80), so the highlighting of long lines doesn't kick in:
(setq whitespace-line-column 250)
I'm assuming that you already have whitespace-mode activated somewhere in your init.el or similar. If so, you can adapt duma's comment above, and either
Edit the elisp that sets whitespace-style to remove lines-tail. E.g., Emacs Prelude sets
(setq whitespace-style '(face tabs empty trailing lines-tail))
Simply change that to
(setq whitespace-style '(face tabs empty trailing))
If you don't want to directly edit that elisp, but rather override it later with your own code, do something like
(setq whitespace-style (delete 'lines-tail whitespace-style))
Unfortunately, if running Prelude with auto-loaded buffers (using something like Emacs Desktop), the initial setting will take precedence: for each buffer on which you want to see whitespace-style displayed as directed, you must [1]
kill the buffer
re-open the buffer
[1]: Note to OP: if there's another way to reload a buffer, please edit or comment this answer. I was hoping to find something like M-x reload-buffer but am not seeing anything like that with C-h a buffer.