×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

cancel ×
This is a preview of your comment

No Comment Title Entered

Anonymous Coward 1 minute ago

No Comment Entered

412 comments

A favourite (works well on both Ubuntu and Debian (4, Funny)

rallymatte (707679) | more than 5 years ago | (#25674781)

I've found this very useful whenever I'm put in front of emacs C-x C-c sudo apt-get -y purge emacs vi

Re:A favourite (works well on both Ubuntu and Debi (5, Funny)

rallymatte (707679) | more than 5 years ago | (#25674787)

There, fixed that for me!

I've found this very useful whenever I'm put in front of emacs
C-x C-c
sudo apt-get -y purge emacs
vi

Re:A favourite (works well on both Ubuntu and Debi (5, Funny)

pivo (11957) | more than 5 years ago | (#25675045)

Hmm.. that didn't work well for me. I tried it, but I ended up in an editor with functionality that was one step above punch cards.

Please Stop (0, Offtopic)

TubeSteak (669689) | more than 5 years ago | (#25674785)

Hopefully this is the last story before we start with "Stupid pet tricks"

Re:Please Stop (2)

Rennt (582550) | more than 5 years ago | (#25674931)

Indeed. If this keeps up we'll need a whole new Stupid Tricks section.

I can see it now -
Useful (Stupid) Things to Say on a Internet Forum!

Re:Please Stop (5, Funny)

alta (1263) | more than 5 years ago | (#25675369)

A whole series...
Useful(Stupid) things to say to get modded Insightful
Useful(Stupid) things to say to get modded Interesting
Useful(Stupid) things to say to get modded Funny
Useful(Stupid) things to say to get modded Troll
Useful(Stupid) things to say to get modded Redundant
Useful(Stupid) things to say to get modded Flamebate
Useful(Stupid) things to say to get modded Overrated
Useful(Stupid) things to say to get modded Stupid
Useful(Stupid) things to say to get modded Useful

Re:Please Stop (4, Funny)

cjfs (1253208) | more than 5 years ago | (#25675205)

Hopefully this is the last story before we start with "Stupid pet tricks"

Seeing as this is about emacs tricks, everything else is a subset. Including pet tricks.

Don't get me wrong: Emacs is a great operating system -- it lacks a good editor, though.

Re:Please Don't Stop (5, Insightful)

Just Some Guy (3352) | more than 5 years ago | (#25675371)

This is the first content I've seen in years that appeals to Slashdot's original demographics: hardcore geeks who are passionate about the tools they use. I've picked up a few tips in this series of articles and have enjoyed hearing other people learn about "old" stuff for the first time.

If "(Stupid) Useful $GEEK Tricks" isn't your cup of tea, then please feel free to look elsewhere [digg.com] .

Huh? (3, Funny)

Anonymous Coward | more than 5 years ago | (#25674825)

the Vi version of this question was both interesting and popular

Indeed. Probably because Vi is a popular and usable text editor (unlike Emacs).

Emacs... (-1, Flamebait)

Anonymous Coward | more than 5 years ago | (#25674855)

...thats 3 letters too many in common with Steve Job's littlest pet shop of horrors play mates.

Thanks, but I'll stick to vi(m)...

Re:Emacs... (1)

xouumalperxe (815707) | more than 5 years ago | (#25675261)

I'll take it you don't eat macaroni then. And that you hated the Macarena. And that you'll steer clear from John Carmack's games. Or...

Troll.

(Full disclaimer: I'm a Mac-loving Vim user)

Re:Emacs... Troll (0)

Anonymous Coward | more than 5 years ago | (#25675337)

well...it worked didn't it? :D

favorite emacs trick (-1, Redundant)

Anonymous Coward | more than 5 years ago | (#25674865)

C-x C-c ; vi filename

grep and emacs integration (5, Interesting)

meta slash (633499) | more than 5 years ago | (#25674869)

Of all the Elisp I've written this grep is what I most miss when I use a coworker's environment.

(defun my-grep ()
  "grep the whole directory for something defaults to term at cursor position"
  (interactive)
  (setq default (thing-at-point 'symbol))
  (setq needle (or (read-string (concat "grep for <" default "> ")) default))
  (setq needle (if (equal needle "") default needle))
  (grep (concat "egrep -s -i -n " needle " * /dev/null")))
(global-set-key "\C-x." 'my-grep)
(global-set-key [f8] 'next-error)

Re:grep and emacs integration (5, Informative)

Anonymous Coward | more than 5 years ago | (#25675121)

Like M-x rgrep? It's builtin now.

Re:grep and emacs integration (3, Interesting)

Beezlebub33 (1220368) | more than 5 years ago | (#25675295)

Damn, and me with no mod points. Someone please mod this up. It is a good example of the neat sort of thing that you can do with emacs.

Since I use Eclipse a lot, I don't use emacs nearly as much as I used to, but there are somethings that emacs just makes easier. One of them is performing a complicated command many times over. I copy from Eclipse, paste in emacs, do a C-x (, do what I need it to do, C-x ), and then C-u 10000 C-x e. Then, copy and paste it back into Eclipse. Saves lots and lots of time.

Here's something I have in my .emacs:

;;--
;; This will count the number of words in a highlighted region
;;--

(global-set-key "\C-x5c" 'word-count )
(defun word-count (start end)
    (interactive "r")
    (let ((words 0) (lines 0) (chars 0))
        (save-excursion
            (goto-char start)
            (while ( (point) end) (forward-word 1) (setq words (1+ words))))
        (setq lines (count-lines start end) chars (- end start))
        (message "Region has %d lines; %d words; %d characters."
                          lines words chars)))

Re:grep and emacs integration (2, Interesting)

Dolda2000 (759023) | more than 5 years ago | (#25675463)

Of all the elisp I've written, this is the one I miss the most when I don't use my own EMACS:

(defun get-previous-buffer (numbufs blist)
  (if (not blist) (signal 'no-such-buffer ()))
  (if (not (buffer-file-name (car blist)))
      (get-previous-buffer numbufs (cdr blist))
    (if (> numbufs 0)
    (get-previous-buffer (1- numbufs) (cdr blist))
      (car blist))))

(defun switch-to-previous-buffer (numbufs)
  "Switches to the previous file-associated buffer in the buffer
list."
  (interactive "p")
  (switch-to-buffer (get-previous-buffer numbufs (buffer-list))))

(global-set-key "\M-\C-m" 'switch-to-previous-buffer)

In short, it allows you to switch back and forth between your two most recently used buffers with M-RET, or between elder buffers with a prefix argument. It's a very convenient alternative to C-x b (though it doesn't replace it, obviously).

Lots of them (4, Interesting)

Anonymous Coward | more than 5 years ago | (#25674891)

M-x tetris
M-x doctor
M-x yow
M-x phases-of-moon

Re:Lots of them (1)

gEvil (beta) (945888) | more than 5 years ago | (#25675091)

Don't forget M-x dunnet

Dead end
You are at a dead end of a dirt road. The road goes to the east.
In the distance you can see that it will eventually fork off. The
trees here are very tall royal palms, and they are spaced equidistant
from each other.
There is a shovel here.
>

Notepad tricks (1, Funny)

Anonymous Coward | more than 5 years ago | (#25674897)

Dear Slashdot,

For us Windows users, I would be very much interested in a similar topic for useful Notepad tricks.
Please take this seriously, and don't say that Alt-F4 (or Alt-F, X) is the best trick.

Yours sincerely,

Fred Anboy

What is next ? (1)

pirhana (577758) | more than 5 years ago | (#25674901)

(Stupid) Userful Bash Tricks ???

Why don't we do the same every week? (2, Interesting)

War Geese (865989) | more than 5 years ago | (#25675315)

We can pick a topic (C++ STL,C++ boost, Eclipse, Electioneering, etc) and then post the many clever/stupid tricks we have learnt.

Some favorites (4, Interesting)

bjourne (1034822) | more than 5 years ago | (#25674923)

(global-set-key (kbd "C-c c") 'comment-dwim)

C-c c to either comment out a region or uncomment it depending on context. Lovely feature.

(global-set-key "\M-g" 'goto-line)

M-g to go to specified line in buffer. Useful for emacs 21.x users where the keybinding is not yet standard.

(menu-bar-mode nil) (scroll-bar-mode nil) (tool-bar-mode nil)

Gets rid of the ugly TK widgets.

(iswitchb-mode t)

Superboosts C-x b.

(global-set-key "\C-z" 'undo)

The normal binding for C-z is suspend-emacs but having it bound as undo is much more useful imo.

Re:Some favorites (2, Informative)

Just Some Guy (3352) | more than 5 years ago | (#25675179)

(global-set-key (kbd "C-c c") 'comment-dwim)

Note: this is already bound to M-; by default.

Re:Some favorites (0)

Anonymous Coward | more than 5 years ago | (#25675471)

(global-set-key (kbd "C-c c") 'comment-dwim)

C-c c to either comment out a region or uncomment it depending on context. Lovely feature.

Already with standard keys: M-;

editing over ssh (5, Informative)

tuffy (10202) | more than 5 years ago | (#25674939)

Always handy when doing a bit of work remotely. Put:

(require 'tramp)
(setq tramp-default-method "scp")

in one's .emacs file. Then open remote files with:

/username@host:remote_path

Favorite Acronym (1)

florescent_beige (608235) | more than 5 years ago | (#25674953)

Forget where I read this...

EMACS: Equine Mammals are Considerably Smaller

Re:Favorite Acronym (1)

Simon Brooke (45012) | more than 5 years ago | (#25675075)

EMACS: Eight Megabytes And Constant Swapping.

GNU Emacs: Generally Not Used Except by Middle Aged Computer Scientists.

(I resemble that remark)

Oh, and, of course, ESC-X doctor - what use is a text editor if it can't psychoanalise you?

Re:Favorite Acronym (1)

soboroff (91667) | more than 5 years ago | (#25675165)

The funny thing is, those jokes about Emacs being slow date back to the 80s. These days, I find that Emacs is about the fastest app to start on a modern Linux distribution.

The rest of userland has gotten fatter and fatter, but Emacs has stayed about the same.

Since the story asks for favorite things about Emacs, I will just add: Gnus. The best email app bar none.

Outlines w/ org-mode (4, Interesting)

Khelder (34398) | more than 5 years ago | (#25674979)

I've recently discovered and almost instantly become a fan of org-mode, which is a great outlining tool (including folding, numbering, and other similar things you'd probably expect).

It's also good for lists of things to do, schedules, deadlines, and related stuff. It uses its own really simple markup langauge (similar to trac wiki), but you can include LaTeX and HTML inline.

It comes with exporters to HTML and LaTeX (and iCal for date stuff). You can also put tables inline, and the table editor is excellent for simple tables.

I use it every day for my list of things to do, and use it regularly for outlining text documents, pseudocode, and meeting notes.

AUCTeX with preview-latex (5, Informative)

P-Nuts (592605) | more than 5 years ago | (#25675027)

When writing scientific papers in LaTeX, there's nothing else that comes close to the power of AUCTeX with preview-latex http://www.gnu.org/software/auctex/preview-latex.html [gnu.org] . It allows you to view typeset equations inline with the rest of the document, but on moving the cursor into an equation, shows the original code. After editing, one brief command, and the new equation is typeset and displayed.

Or you can just... (1)

jonaskoelker (922170) | more than 5 years ago | (#25675561)

After editing, one brief command, and the new equation is typeset and displayed.

You could just use fontenc and set up a good ~/.XCompose that lets you input most of the symbols you need.

There's no \mathbb{F} that I could find, and taller-than-one-line \Sigma{}s don't show up well in an xterm. But it works.

macros are cool (3, Informative)

Anonymous Coward | more than 5 years ago | (#25675029)

C-x ( -- start a macro definition

-- type some commands

C-x ) -- end the macro

C-x e -- execute the last macro

For certain repetitive tasks which didn't warrent a new script I though this macro capability was awesome.

Not much of a trick... BUT... (2, Insightful)

McNihil (612243) | more than 5 years ago | (#25675031)

CTRL-X 1|2|3 to divide the editing area according to wish. I simply can't live without this functionality.

Now if anyone makes a Firefox plugin making it possible to do the same in a web browser that would be friggin awesome.

Re:Not much of a trick... BUT... (1, Informative)

Anonymous Coward | more than 5 years ago | (#25675285)

you can actually do something similar with Konqueror:
Window -> Split View Left/Right or Split View Top/Bottom.

it also comes with keyboard shortcuts.

Re:Not much of a trick... BUT... (2, Funny)

homer_s (799572) | more than 5 years ago | (#25675291)

Now if anyone makes a Firefox plugin making it possible to do the same in a web browser that would be friggin awesome.

So, you don't use Emacs to browse the web?

Edit files from anywhere w/ tramp (4, Informative)

Khelder (34398) | more than 5 years ago | (#25675037)

One of my favorite emacsisms a long time ago was ange-ftp, and the modern descendant, tramp, is one of my current faves. It lets you edit remote files over lots of protocols, including: ssh, scp, ftp, rsync, ftp, and smb.

Most emacs stuff works transparently, like dired and archive browsing. When you edit a file and save it, it's automatically put back on the remote machine. I have had trouble with psvn, but that's about the only thing that I kinda expected to work that didn't.

If you edit remote files and you use emacs, you want to start using this.

Editing recorded keystrokes (2)

david.emery (127135) | more than 5 years ago | (#25675065)

A couple of times the ability of Emacs to record keystrokes and then edit them has been a real power tool, particularly when I've needed to do very complex edits over a set of files.

So I'd record edits on the first file, look at the keyboard recording (doing any substitutes if necessary), bind that to a key combination, then iterate over the list of files. Now if I were a good Emacs hacker, I could have automated the iteration step, too :-)

Re:Editing recorded keystrokes (1)

Beezlebub33 (1220368) | more than 5 years ago | (#25675347)

How do you see the keyboard recording?

Re:Editing recorded keystrokes (2, Informative)

david.emery (127135) | more than 5 years ago | (#25675537)

This is covered in Chapter 10 of that invaluable reference "Learning GNU Emacs" (now in its 3rd edition, I need to 'upgrade' my 1st edition so the chapter organization might have changed) (http://oreilly.com/catalog/9780596006488/index.html)

You can do M-x apropos macro to get info. There's an edit-kbd-macro command as well as a whole bunch of other useful things.

dave

I replaced it (2, Interesting)

ColonelPanic (138077) | more than 5 years ago | (#25675073)

After 25 years of vi and Emacs, I got fed up and wrote something better. And at 6k lines of C, it's not much bigger than my .emacs file was. :-)

Seriously, people: you don't have to live with the available options. Writing an editor is a easy job.

And yes, I GPL'd it. Have fun.

http://code.google.com/p/aoeui/ [google.com]

Re:I replaced it (1)

fortunatus (445210) | more than 5 years ago | (#25675409)

you waited 25 years? in 1982 my girlfriend wrote an editor for the freshman data structures class at our university. some folks used their editors from then on through school.

Stupid trick #1 (0)

Anonymous Coward | more than 5 years ago | (#25675083)

Stupid trick #1: Vi emulation.

Turning an excellent editor into a piece of rubbbihs,

Modifying variables (2, Informative)

dkf (304284) | more than 5 years ago | (#25675113)

If you've got a file that you always want to set some specific variable to a non-default value for when editing, use something like this (taken from the end of a C file...)

/*
  * Local Variables:
  * fill-column: 78
  * c-basic-offset: 4
  * End:
  */

Young people being led astray? (-1, Flamebait)

Anonymous Coward | more than 5 years ago | (#25675117)

I hope that this recent wave of vi and emacs posts is due to old guys, not young guys.

It would be tragic to think that bad habits from 20 years ago would be inflicted on a new generation.

We interviewed a candidate for a sysadmin position. He saw nano on a screen and made a comment: "who's the newbie?"

So I asked him to compile and install mysql from source on a test box. He flailed.

Open jars, wars, ears with archive-mode (2, Informative)

wytten (163159) | more than 5 years ago | (#25675129)

Configure emacs auto-mode-alist to open Java archives with archive-mode, and then edit deployment descriptors contained in the archive without having to extract the archive. Bliss.

Window switching (0)

Anonymous Coward | more than 5 years ago | (#25675155)

I only started to feel like I was beginning to have a clue with emacs when I learned to manage windows .. from then on the learning curve is easy because you're no longer humiliated by the inability to do something you take for granted so much in any GUI

C-x 3 split vertically
C-x 2 split horizontally
C-x o change to the other window
C-x 1 delete the opposite window
C-x 0 delete all other windows

Org-mode is really neat also

m-x org mode
m-x-describe-bindings / C-h b

Also you can use the meta key to access almost any command that also has a C- combination, by its literal full name. You can then use tab completion to jog your memory

eg.

m-x desc gives you the hint for the above, and when the command runs the minibuffer tells you to try C-h b next time

Emacs is surprisingly user friendly, once you get into into the swing of things!

recentf mode (1)

wytten (163159) | more than 5 years ago | (#25675201)

recentf mode, which keeps a list of recently opened files:

(require 'recentf)
(recentf-mode 1)

For bonus points, set a PROJECT environment variable before starting eclipse, and maintain project-specific lists of recently opened files:

(when (getenv "PROJECT")
    ; project-specific recently opened files
    (setq recentf-save-file (concat (getenv "PROJECT") "/.recentf"))
    ; project-specific emacs config
    (when (file-exists-p (concat (getenv "PROJECT") "/.emacs"))
        (load-file (concat (getenv "PROJECT") "/.emacs")))
    ; project-specific TAGS file
    (when (file-exists-p (concat (getenv "PROJECT") "TAGS"))
        (visit-tags-table (concat (getenv "PROJECT") "TAGS"))))

some of mine (5, Informative)

flynt (248848) | more than 5 years ago | (#25675213)

1)First, ESS, Emacs speaks statistics, found at http://ess.r-project.org/ [r-project.org] . This lets you interface interactively with R, SAS, Stata, etc., all from the common Emacs interface. As a statistician, it's the one piece of software I could not do very well without!

2) The 'ido' package, with flex matching, in my .emacs,

(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)

This lets you open files and switch buffers with fuzzy matching, really nice when you have lots of things open.

See: http://www.emacsblog.org/2008/05/19/giving-ido-mode-a-second-chance/ [emacsblog.org]

3) Make the mouse jump away when you type over it.
(mouse-avoidance-mode 'cat-and-mouse)

4) Open two windows side-by-side (C-x 3) one with LaTeX code, one with a pdf, then use this in your .emacs, (add-hook 'doc-view-mode-hook 'auto-revert-mode), when you compile the .tex file into PDF, the PDF automatically updates in Emacs, I used that a lot while working on my CV.

5) The thunderbird extension that lets me compose replies in Emacs using emacsclient.

6) org-mode http://www.org-mode.org/ [org-mode.org]

7) preview-latex, now part of AUCTeX, this lets you see preview versions of formulae and graphics inline in your .text file, *while you edit*. Your formula is replaced by what it will look like when compiled.

8) EmacsWiki: http://www.emacswiki.org/ [emacswiki.org]

One reason why VI is better... (-1)

Anonymous Coward | more than 5 years ago | (#25675219)

Efficiency via less key strokes.

Ctrl-X, Ctrl-C (-1, Redundant)

Anonymous Coward | more than 5 years ago | (#25675231)

Ctrl-X, Ctrl-C

Because you shouldn't be using Emacs.

Check hard drive (4, Funny)

digitalhermit (113459) | more than 5 years ago | (#25675237)

It's often the case when you need to check the sectors on your disk for corruption, or just during hard drive testing. One of the coolest things that Emacs allows you to do is check your filesystem. For example on CentOS:

      yum -y install emacs*

This will proceed to fill up your hard drive with tons of software until the filesystem is full.

(I kid, I kid)

Emacs Lisp (4, Funny)

tjwhaynes (114792) | more than 5 years ago | (#25675241)

Lisp is a language that CompScis see for two months at University before leaving it behind. But if you really want to learn tricks with Emacs, you should learn Emacs Lisp - I have all sorts of specials, such as "move text to marker" and modes for handling internal IBM dump formats, that would be impossible in vi.

But if you want one quick piece of advice, here's one that should make someone smile

M-x hippie-expand RET

The ultimate, expand-this-thing-dammit-from-whatever-you-like completion trick.

Cheers,
Toby Haynes

Re:Emacs Lisp (1)

TheRaven64 (641858) | more than 5 years ago | (#25675401)

While I usually consider ESR to be an idiot, he did say something sensible about Lisp:

LISP is worth learning for a different reason â" the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot

EMACS is a fantastic Lisp environment (although it's a shame that most people use the C version now - EMACS on MULTICS was written in Lisp and so introspection and reflection worked everywhere, and most Lisp machines came with a version too). I'm not a huge fan of it as a text editor, but every time I write a script in Vim's scripting language I consider switching.

The apocryphal command (3, Funny)

digitalderbs (718388) | more than 5 years ago | (#25675249)

I once knew a man that typed an emacs sequence, once locked in hidden, ancient papyri. Emacs conducted all of the research for his PhD, typed his dissertation, correctly formatted his bibliography (the most astounding feat of all), setup the defense with his advisory committee, presented and defended his thesis, printed, bound and submitted the dissertation.

Re:The apocryphal command (0)

Anonymous Coward | more than 5 years ago | (#25675383)

I'm using the same methodology right now, the magic command is M-x psychoanalyze-pinhead :)

Re:The apocryphal command (1, Funny)

Anonymous Coward | more than 5 years ago | (#25675435)

I know that man, I am his boss now. Imagine had he used vim, like me...

align-regexp (3, Interesting)

Just Some Guy (3352) | more than 5 years ago | (#25675265)

(Pretend that '.'==' ' because Slashdot hates programmers.)

Before:

a.= 1
longer.= 2
some_variable.= None
foo.= 'bar'

After running M-xalign-regexp=:

a...............= 1
longer..........= 2
some_variable...= None
foo.............= 'bar'

C-u to delete line backward (1, Interesting)

Anonymous Coward | more than 5 years ago | (#25675279)

(defun my-kill-prev-line ()
  "Kills from the cursor to the beginning of the line."
  (interactive)
  (kill-line 0))
(global-set-key "\C-u" 'my-kill-prev-line)

Makes Control-U do what it does in every other place on your computer.

Keyboard macros and query-replace-regexp (1)

try_anything (880404) | more than 5 years ago | (#25675293)

There are a two general and powerful emacs tools that every user should know: keyboard macros and query-replace-regexp.

To record a keyboard macro, hit C-x ( to start recording, type your macro, and hit C-x ) to stop. Bind F5 or another function key to call-last-kbd-macro so it's easy to run a macro many times.

Then practice ;-) Learn to use C-a, C-e, and incremental search in your macros, so you can just hit F5 F5 F5... to perform a repetitive editing task across an entire file. You will be slow at composing the macros at first, but once you get the hang of it, you'll want to do everything using keyboard macros. (That might be a reasonable approach for some folks, but I recommend you keep going -- there's treasure everywhere!)

Once you're good at keyboard macros, the next thing to learn is query-replace-regexp. The hardest thing about query-replace-regexp is that emacs regexp syntax is a bit of an outlier in the regexp family. Once you get over that (which I haven't entirely) you're a ninja.

After those two, you should google around for more tips of enthusiastic emacs users, and generally keep an ear to the ground. Occasionally you'll hear of some command that is a perfect fit for your work or your brain or both.

Finally, elisp programming is essential for serious users. You don't have to immediately set aside time to learn it, but definitely do not shy away from it when you need it. You'll need a very basic understanding to tweak your .emacs file, and your knowledge can grow from there. I've only written half a dozen elisp functions for editing (rather than configuration) but I use a couple of them at least once a week. The first editing command I created in elisp took me half a day to write and debug, but then I used it dozens of times a day for three weeks -- pretty good ROI!

My Favorite... (3, Funny)

awshidahak (1282256) | more than 5 years ago | (#25675305)

is M-x Viper \[esc]x eshell All the obscureness of vim combined with the bloat of emacs. Then I have lots of fun letting people borrow my computer and watch them get mad at my custom xmodmap while trying to figure out how to get to the "Start" menu because they don't know ratpoison.

Re: (2, Interesting)

Anonymous Coward | more than 5 years ago | (#25675355)

For GNU emacs:

        (require 'ffap)

This means "find file at point." If the cursor is on anything that looks like a file (or URL, etc) it'll try to do the right thing for you automatically. RTFM for delicious details.

"M-q" will reindent a paragraph nicely.
"C-x ." will set a fill prefix, i.e., if you need to reparagraph something with the " >" prefix for mail replies

Keyboard macros are great for mass editing files. "C-x (" to start recording, "C-x )" to stop, "C-x e" to execute. Once you've got the macro working, repeat as needed, "C-u 99 C-x e".

Beginning of line (5, Informative)

vslashg (209560) | more than 5 years ago | (#25675361)

My two .emacs modifications I find essential follow.

First, turning off of obnoxious misfeatures:

(fset 'yes-or-no-p 'y-or-n-p) ; stop forcing me to spell out "yes"
(setq inhibit-startup-message t)
(setq backup-directory-alist '(("." . "~/.emacs-backups"))) ; stop leaving backup~ turds scattered everywhere

And second, stealing the beginning-of-line behavior from Dev Studio: if you invoke the command at the beginning of the line, advance to the first non-whitespace-character instead.

(defun dev-studio-beginning-of-line (arg)
  "Moves to beginning-of-line, or from there to the first non-whitespace character.
 
This takes a numeric prefix argument; when not 1, it behaves exactly like
\(move-beginning-of-line arg) instead."
  (interactive "p")
  (if (and (looking-at "^") (= arg 1)) (skip-chars-forward " \t") (move-beginning-of-line arg)))
(global-set-key "\C-a" 'dev-studio-beginning-of-line)
(global-set-key [home] 'dev-studio-beginning-of-line)

I don't know how I programmed without this (1)

dollargonzo (519030) | more than 5 years ago | (#25675485)

This is some e-lisp to do auto-completion (using dabbrev-expand). If after a semicolon at the end of a line or in the initial whitespace, TAB will indent as usual, otherwise it will auto-complete. C-TAB is mapped to always indent

(add-hook 'c-mode-common-hook 'autotab)
(add-hook 'perl-mode-hook 'autotab)
(add-hook 'cperl-mode-hook 'autotab)

(defun dabbrev-quick ()
    (interactive)
    (if (save-excursion
                (if (not (looking-at "^")) (backward-char))
                (while (and (looking-at "[ \t]") (not (looking-at "^"))) (backward-char))
                (looking-at "^\\|;")) (indent-for-tab-command) (dabbrev-expand nil))
)

(defun autotab ()
    (local-set-key [tab] 'dabbrev-quick)
    (local-set-key [C-tab] 'indent-for-tab-command)
)

trying to figure something out (4, Funny)

viridari (1138635) | more than 5 years ago | (#25675491)

I like emacs but I'm not ready to change over to it 100% yet.

Is there a way to dual boot between Vista and emacs?

C/C++ Fast File Editing (1)

yumyum (168683) | more than 5 years ago | (#25675509)

;;
;; Functions to find the 'twin' of the currently-edited file. For instance,
;; executing my-c-find-twin [C-C C-f]] while editing a *.cc file will
;; bring up in a different buffer the *.h file that matches the '*'.
;;

(defun my-c-find-file-with-extension (base extensions default)
  (if (null extensions)
      (concat base "." default)
    (let ((filename (concat base "." (car extensions))))
      (if (file-exists-p filename)
      filename
    (my-c-find-file-with-extension base (cdr extensions) default)))))

(defun my-c-twin-file ()
  ""
  (let ((extension (file-name-extension (buffer-file-name)))
    (sans (file-name-sans-extension (buffer-file-name))))
    (cond
     ((string-match "[hH]\\(pp\\)?" extension)
      (cond
       ((string-equal "ObjC" mode-name)
    (my-c-find-file-with-extension sans '("m" "mm") "mm"))
       ((string-equal "C++" mode-name)
    (my-c-find-file-with-extension sans '("cc" "cpp" "C") "cc"))
       (t
    (my-c-find-file-with-extension sans '("m" "mm" "cc" "cpp"
                          "c" "C" "cp") "cc"))))
     (t
      (my-c-find-file-with-extension sans '("h" "hpp") "h")))))

(defun my-c-find-twin ()
  ""
  (interactive)
  (find-file (my-c-twin-file)))

(defun my-c-find-twin-other-window ()
  ""
  (interactive)
  (find-file-other-window (my-c-twin-file)))

(defun my-c-find-twin-other-frame ()
  ""
  (interactive)
  (find-file-other-frame (my-c-twin-file)))

(defun my-c-mode ()
  (unless (boundp 'my-c-c-c-4-keymap)
    (define-prefix-command 'my-c-c-c-4-keymap))

  (local-set-key [(control c)(control f)] 'my-c-find-twin)

  (local-set-key [(control c)(?4)] 'my-c-c-c-4-keymap)
  (local-set-key [(control c)(?4)(?f)] 'my-c-find-twin-other-window)

  (unless (boundp 'my-c-c-c-5-keymap)
    (define-prefix-command 'my-c-c-c-5-keymap))

  (local-set-key [(control c)(?5)] 'my-c-c-c-5-keymap)
  (local-set-key [(control c)(?5)(?f)] 'my-c-find-twin-other-frame)

  (show-paren-mode t))

A few of my favorite things (0)

Anonymous Coward | more than 5 years ago | (#25675535)

My favorite extensions are GNUS, VM, pcl-cvs, and psvn.

My favorite extension that I do not actually use is AUC-TeX.

My favorite extension that I wrote is scroll-in-place.

The command that gets me the most mileage when people ask me how to do some crazy editing task is query-replace-regexp.

Best wishes ---

Eric.

The old Emacs vs Vi story (5, Funny)

raffe (28595) | more than 5 years ago | (#25675563)

I asked my email-pal: "UNIX or Windoze?". He replied "UNIX". I said "Ah...me too!".

I asked my email-pal: "Linux or AIX?". He said "Linux, of course". I said "Me too".

I asked him: "Emacs or vi". He replied "Emacs". I said "Me too. Small world."

I asked him: "GNU Emacs or XEmacs?", and he said "GNU Emacs". I said "oh, me too."

I asked him "GNU Emacs 19 or GNU Emacs 20"? and he said "GNU Emacs 19". I said "oh, me too."

I asked him, "GNU Emacs 19.29 or GNU Emacs 19.34", and he replied "GNU Emacs 19.29". I said "DIE YOU OBSOLETE NOGOOD SOCIALLY MALADJUSTED CELIBATE COMMIE FASCIST DORK!", and never emailed him again.

From an old slashdot [slashdot.org] story

Two tips for trailing whitespace (2, Informative)

stevey (64018) | more than 5 years ago | (#25675581)

There are a lot of things that you can do with Emacs, but I find the two simplest to share would be related to trailing whitespace:

;; Show trailing whitespace by default
(when (>= emacs-major-version 21)
(setq-default show-trailing-whitespace t))

;;
;; kill trailing white space on save
;;
(add-hook 'write-file-hooks
'delete-trailing-whitespace)

Load More Comments
Slashdot Account

Need an Account?

Forgot your password?

Don't worry, we never post anything without your permission.

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>
Sign up for Slashdot Newsletters
Create a Slashdot Account

Loading...