You are not logged in.

#1 2009-07-23 18:22:54

Allamgir
Member
Registered: 2009-06-11
Posts: 168

[SOLVED] Emacs longlines-mode for all .txt and .tex files?

I recently made the plunge into gnu emacs but missed my beloved feature of soft word wrap that I could even get right in vim with minimal effort. I was able to find this guide that allows me to get soft word wrap working by manually doing

M-x longlines-mode

The problem is I have to do that every single time I open a document I want to wrap. I don't want to wrap all documents, only ones ending in .txt and .tex. Right now this is my ~/.emacs:

(autoload 'longlines-mode "longlines.el" "Minor mode for editing long lines." t)

What should I put in this to make it so every time I open a txt or tex document, emacs automatically does M-x longlines-mode for me?

Last edited by Allamgir (2009-07-24 21:46:12)


дɭɭɑӎɠїɾ

Offline

#2 2009-07-23 18:52:48

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

;; Wrap lines at 70 for txt mode
;(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Enable longlines mode
(add-hook 'text-mode-hook 'longlines-mode)

You need to install an RTFM interface.

Offline

#3 2009-07-23 19:07:27

Allamgir
Member
Registered: 2009-06-11
Posts: 168

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

Awesome! Thank you so much! I'm definitely going to consider switching to emacs full time. The "Emacs pinky" worries me, but I don't use a computer more than 4-5 hours in one day, at most, and I don't put much pressure on my fingers because my keyboard accepts input with very little.

Meh, maybe it's just some cult of vi propaganda to scare people from emacs.


дɭɭɑӎɠїɾ

Offline

#4 2009-07-23 19:15:59

Allamgir
Member
Registered: 2009-06-11
Posts: 168

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

Uh, oh. I think this line breaking messed up the emacs tutorial. now I have all sorts of strange indentations mid-sentence and the words are soft wrapping. Maybe I should have finished the tutorial before I went messing with the word wrap.


дɭɭɑӎɠїɾ

Offline

#5 2009-07-23 19:16:34

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

The "Emacs pinky" worries me, but I don't use a computer more than 4-5 hours in one day

I've been using Emacs for a long time, and avoiding the mouse in general as much as possible, you can read how I manage (and learn from my mistakes) here http://sysphere.org/~anrxc/j/archives/2 … index.html

Last edited by anrxc (2009-07-23 19:18:51)


You need to install an RTFM interface.

Offline

#6 2009-07-24 01:44:20

Allamgir
Member
Registered: 2009-06-11
Posts: 168

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

Also, this doesn't work in tiling window managers. I'm using dwm right now and all the text is limited to (I think) 70 characters per line. This is really awkward when editing with a fullscreen terminal. Hopefully there's a solution for this rather than switching to openbox.


Instead of 70 characters per line as the limit, is there a way to change ~/.emacs to wrap lines at 4 characters less than the current terminal width?

Last edited by Allamgir (2009-07-24 01:48:33)


дɭɭɑӎɠїɾ

Offline

#7 2009-07-24 04:35:29

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

Allamgir wrote:

Awesome! Thank you so much! I'm definitely going to consider switching to emacs full time. The "Emacs pinky" worries me, but I don't use a computer more than 4-5 hours in one day, at most, and I don't put much pressure on my fingers because my keyboard accepts input with very little.

Just use your off-hand to press Control the same as you do with shift keys (e.g. use right Control with "a" and left control with "p") and I doubt you'll ever have a problem.

I think setting fill-column is the way to go about it. If you want to change this based on the window width, there's probably a resize hook you could add something like (lambda () (setq fill-column (- (window-width) 4))) to. I don't use longlines-mode though, so maybe that's wrong.

Last edited by pauldonnelly (2009-07-24 04:45:01)

Offline

#8 2009-07-24 14:48:35

Allamgir
Member
Registered: 2009-06-11
Posts: 168

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

Thanks for the post. I'll try that line and see if it works. If not, then hopefully someone can help fix that line.

Also, I learned that longlines is built into emacs 22, so I don't need that longlines.el script. It just doesn't do soft wraps based on window size properly, but on a fixed number of characters.

EDIT: Unfortunately that doesn't work. This is my current ~/.emacs:

;; Wrap lines at 70 for txt mode
;(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Enable longlines mode
(add-hook 'text-mode-hook 'longlines-mode)
(lambda () (setq fill-column (- (window-width) 4)))

I get no errors when I start emacs, but I still have word wrapping at 70 characters for .txt and .tex files, regardless of the terminal window size. I'm on my mac right now, but the behavior should be the same when I resize the terminal window.

Last edited by Allamgir (2009-07-24 17:48:53)


дɭɭɑӎɠїɾ

Offline

#9 2009-07-24 21:45:52

Allamgir
Member
Registered: 2009-06-11
Posts: 168

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

YES! I got it! All I had to do was add this line to my .emacs:

(setq longlines-wrap-follows-window-size t)

smile

This is my current .emacs:

(require 'tex-site)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
;; Wrap lines at 70 for txt mode
;(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Enable longlines mode
(add-hook 'text-mode-hook 'longlines-mode)
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
(autoload 'longlines-mode "longlines.el" "Minor mode for editing long lines." t)
(setq longlines-wrap-follows-window-size t)

YES! DONE! I HAVE COME TO YOU, EMACS! YOU WILL NOW BE MY PRIMARY TEXT EDITOR!



Thanks so much to all of you that helped. I can finally mark this thread [SOLVED]


дɭɭɑӎɠїɾ

Offline

#10 2009-07-26 16:21:46

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: [SOLVED] Emacs longlines-mode for all .txt and .tex files?

Allamgir wrote:
;; Wrap lines at 70 for txt mode
;(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Enable longlines mode
(add-hook 'text-mode-hook 'longlines-mode)
(lambda () (setq fill-column (- (window-width) 4)))

I see you've fixed it (good job reading the docs wink ), but I still want to point out that the last line there does absolutely nothing, so of course it doesn't fix the problem. It's as if you had typed 3, or "foo" there. It just creates and discards an anonymous function.

Offline

Board footer

Powered by FluxBB