Slashdot Mirror


(Stupid) Useful Emacs Tricks?

Count Fenring writes "Since the Vi version of this question was both interesting and popular, let's hear from the other end of the spectrum. What are your favorite tricks, macros, extensions, and techniques for any of the various Emacs? Myself, I like 'M-x dunnet' ;-)"

90 of 412 comments (clear)

  1. A favourite (works well on both Ubuntu and Debian by rallymatte · · Score: 4, Funny

    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

  2. Re:A favourite (works well on both Ubuntu and Debi by rallymatte · · Score: 5, Funny

    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

  3. XKCD by WK2 · · Score: 5, Funny

    C-X M-C M-butterfly

    --
    Write your own Choose Your Own Adventure. http://www.freegameengines.org/gamebook-engine/
  4. Huh? by Anonymous Coward · · Score: 3, Funny

    the Vi version of this question was both interesting and popular

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

    1. Re:Huh? by ByOhTek · · Score: 2, Insightful

      deletions, and ONLY deletions from a file. If there is any adding/changing, I'd sooner sue cat+sed.

      --
      Self proclaimed typo king, and inventor of the bear destroying coffee table (patent not pending).
    2. Re:Huh? by Dr+Caleb · · Score: 3, Funny

      I don't think cat+sed has any money. Plus, you'd have to prove damages.

      --
      "History doesn't repeat itself, but it does rhyme." Mark Twain
    3. Re:Huh? by Anonymous Coward · · Score: 5, Funny

      Emacs has a text editor now?

    4. Re:Huh? by volxdragon · · Score: 2, Insightful

      See, there's your problem....Emacs isn't a text editor, it's a development environment with a Turing-complete language in it.

    5. Re:Huh? by yukk · · Score: 2, Insightful

      Emacs has a text editor now?

      See, this is why I hate mod points. They're never around when you need them.

      --
      The trouble with the rat race is that even if you win, you're still a rat." Lily Tomlin
  5. grep and emacs integration by meta+slash · · Score: 5, Interesting

    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)

    1. Re:grep and emacs integration by Anonymous Coward · · Score: 5, Informative

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

    2. Re:grep and emacs integration by Beezlebub33 · · Score: 3, Interesting

      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)))

      --
      The more people I meet, the better I like my dog.
    3. Re:grep and emacs integration by Dolda2000 · · Score: 2, Interesting

      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).

    4. Re:grep and emacs integration by gowen · · Score: 5, Informative

      Isn't that usually spelled

      M-| wc

      Meta-pipe is a great one -- it's "pipe region to external command" (M-x shell-command-on-region)

      --
      Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
  6. Lots of them by Anonymous Coward · · Score: 4, Interesting

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

    1. Re:Lots of them by jbaltz · · Score: 2, Insightful

      M-x psychoanalyze-pinhead

      --
      I am the Lorvax, I speak for the machines.
    2. Re:Lots of them by haystor · · Score: 3, Interesting

      C-x r k ;; kill-rectangle
      C-x r y ;; yank-rectangle

      Cut and paste columns of text.

      --
      t
  7. Re:A big disappointment by include($dysmas) · · Score: 5, Funny

    it was posted from emacs, took a while to press all the keys.

  8. Some favorites by bjourne · · Score: 4, Interesting

    (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.

    1. Re:Some favorites by Just+Some+Guy · · Score: 2, Informative

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

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

      --
      Dewey, what part of this looks like authorities should be involved?
    2. Re:Some favorites by patro · · Score: 2, Interesting

      If we consider external packages too:

      The QuickSilver for Emacs: anything.el

    3. Re:Some favorites by Dolda2000 · · Score: 3, Insightful

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

      You mention undo only as such, but I'd like to add that the undo functionality really is one of Emacs' killer functions. See, when you undo a string of commands in Emacs, it doesn't just discard that part of the undo history as most (all?) other editors do, but it folds it backwards onto the undo stack, which is unbelievably useful.

      I often use it as a sort of short-term, local version control. I can type something, try it, undo it and type something else, try that, and then undo back to the first version if I weren't satisfied with the second. It also enables me to use undo as a sort of short-term memory extension in that I can hack around a bit, and then interrupt myself for a visit to the toilet or similar. Then, when I get back, I can check exactly what I was doing before I left by just undoing a bit, and then undo the undoings.

      I don't think I'd ever be able to use an editor that doesn't have Emacs' killer undo.

  9. Re:Please Stop by Rennt · · Score: 2

    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!

  10. editing over ssh by tuffy · · Score: 5, Informative
    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

    --

    Ita erat quando hic adveni.

  11. Re:What is next ? by rallymatte · · Score: 2, Informative

    Well no, there were loads of bash tricks in the (Stupid) Useful Unix Tricks.

  12. Outlines w/ org-mode by Khelder · · Score: 4, Interesting

    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.

  13. AUCTeX with preview-latex by P-Nuts · · Score: 5, Informative

    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. 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.

  14. macros are cool by Anonymous Coward · · Score: 3, Informative

    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.

    1. Re:macros are cool by Haeleth · · Score: 2, Informative

      This feature is built into C-x e as well: `C-x e e e e e' is exactly the same as `C-x e C-x z z z z'. :)

  15. Not much of a trick... BUT... by McNihil · · Score: 2, Insightful

    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.

    1. Re:Not much of a trick... BUT... by homer_s · · Score: 2, Funny

      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?

  16. Edit files from anywhere w/ tramp by Khelder · · Score: 4, Informative

    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.

    1. Re:Edit files from anywhere w/ tramp by Risen888 · · Score: 3, Interesting

      Tramp is also extremely useful for editing files as root without opening a root emacs session. If you use sudo on your system, it's C-x C-f /sudo::/path/to/file, or su: C-x C-f /root@localhost:/path/to/file.

      --
      Hey, I finally got my first freak! Took you long enough!
  17. Re:A favourite (works well on both Ubuntu and Debi by pivo · · Score: 5, Funny

    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.

  18. Editing recorded keystrokes by david.emery · · Score: 2

    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 :-)

    1. Re:Editing recorded keystrokes by david.emery · · Score: 2, Informative

      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

  19. I replaced it by ColonelPanic · · Score: 2, Interesting

    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/

    --
    "Skill shows through where genius wears thin." -Wittgenstein || Religion: uniting aviation and architecture.
    1. Re:I replaced it by MosesJones · · Score: 3, Insightful

      Congratulations, beating out hot favourites Karl Rove and Dick Cheney you have just won single most arrogant statement of the year

      "I wrote something better"

      When you get several million users then call, until then you've got a pet project doing something that loads of people before you have done, and lots of people after you have done.

      and more people will still be using VI and Emacs

      --
      An Eye for an Eye will make the whole world blind - Gandhi
    2. Re:I replaced it by dunkelfalke · · Score: 2, Insightful

      there are far more notepad users than vi and emacs users together.
      that does not mean, that notepad is a great text editor, though.

      --
      "It's such a fine line between stupid and clever" -- David St. Hubbins, Spinal Tap
  20. My fave by scubamage · · Score: 2, Interesting

    M-x hanoi - plays tower of hanoi for n number of towers

  21. Modifying variables by dkf · · Score: 2, Informative

    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:
      */

    --
    "Little does he know, but there is no 'I' in 'Idiot'!"
  22. Open jars, wars, ears with archive-mode by wytten · · Score: 2, Informative

    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.

  23. Mistake made by jez9999 · · Score: 2, Informative

    I think this article has been incorrectly filed; please fix, editors. It's been put under "News".

  24. Re:Please Stop by cjfs · · Score: 4, Funny

    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.

  25. there's a whole wiki to answer this question by felipecs · · Score: 5, Informative
  26. some of mine by flynt · · Score: 5, Informative

    1)First, ESS, Emacs speaks statistics, found at http://ess.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/

    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/

    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/

  27. Meta-/ by giblfiz · · Score: 4, Informative

    auto completes based on words that have been seen in the buffer.

  28. Check hard drive by digitalhermit · · Score: 4, Funny

    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)

  29. Emacs Lisp by tjwhaynes · · Score: 4, Funny

    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

    --
    Anything I post is strictly my own thoughts and doesn't necessarily have anything to do with the opinions of IBM.
  30. The apocryphal command by digitalderbs · · Score: 3, Funny

    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.

  31. Obligatory link by fprintf · · Score: 3, Informative
    --
    This post brought to you by your friendly neighborhood MBA.
  32. align-regexp by Just+Some+Guy · · Score: 3, Interesting

    (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'

    --
    Dewey, what part of this looks like authorities should be involved?
  33. My Favorite... by awshidahak · · Score: 3, Funny

    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.

  34. Why don't we do the same every week? by War+Geese · · Score: 2, Interesting

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

  35. zippy the pinhead! by sl0ppy · · Score: 2, Informative

    M-x yow

    and of course, the ever relevant:

    M-x psychoanalyze-pinhead

  36. Re: by Anonymous Coward · · Score: 2, Interesting

    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".

  37. Beginning of line by vslashg · · Score: 5, Informative

    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)

  38. Re:Notepad tricks by gEvil+(beta) · · Score: 2, Insightful

    Well, if you're using Windows XP, the best trick is Win-U-U.

    --
    This guy's the limit!
  39. Re:Please Stop by alta · · Score: 5, Funny

    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

    --
    Do not meddle in the affairs of sysadmins, for they are subtle, and quick to anger.
  40. Re:Please Don't Stop by Just+Some+Guy · · Score: 5, Insightful

    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.

    --
    Dewey, what part of this looks like authorities should be involved?
  41. trying to figure something out by viridari · · Score: 4, Funny

    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?

  42. The old Emacs vs Vi story by raffe · · Score: 5, Funny

    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 story

    1. Re:The old Emacs vs Vi story by sootman · · Score: 2, Funny

      As the original post hints, this is an adaptation of and old Emo Phillips bit.

      I was walking across a bridge one day, and I saw a man standing on the edge, about to jump off. So I ran over and said "Stop! don't do it!"
      "Why shouldn't I?" he said.
      I said, "Well, there's so much to live for!"
      He said, "Like what?"
      I said, "Well...are you religious or atheist?"
      He said, "Religious."
      I said, "Me too! Are you christian or buddhist?"
      He said, "Christian."
      I said, "Me too! Are you catholic or protestant?"
      He said, "Protestant."
      I said, "Me too! Are you episcopalian or baptist?"
      He said, "Baptist!"
      I said,"Wow! Me too! Are you baptist church of god or baptist church of the lord?"
      He said, "Baptist church of god!"
      I said, "Me too! Are you original baptist church of god, or are you reformed baptist church of god?"
      He said,"Reformed Baptist church of god!"
      I said, "Me too! Are you reformed baptist church of god, reformation of 1879, or reformed baptist church of god, reformation of 1915?"
      He said, "Reformed baptist church of god, reformation of 1915!"
      I said, "Die, heretic scum", and pushed him off.

      --
      Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
  43. Re:What is next ? by kv9 · · Score: 4, Funny

    (Stupid) Useful Chat-up Lines

    hey, sexy mama. wanna kill all the humans?

  44. Two tips for trailing whitespace by stevey · · Score: 2, Informative

    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)

  45. Re:A favourite (works well on both Ubuntu and Debi by aproposofwhat · · Score: 3, Funny

    I started on punch cards, you insensitive clod!

    --
    One swallow does not a fellatrix make
  46. Completion and incremental search are... by StressedEd · · Score: 2, Interesting
    very useful and extremely simple. Assuming [M] means "Meta-key".

    [M]/ Will attempt to complete the current word. This is done working backwards from the edit point and can look in other buffers.

    If (for example) you are editing a LaTeX document and you wish to cross reference an existing figure with label \label{f:my-figure} entering the following:

    \ref{f:[M]/ will repeatedly try to match everything starting with f: , namely all the existing figure labels.

    Likewise if referencing a citation in a BibTeX file that is open in another buffer, \cite{startofkey[M]/ works a treat!

    Incremental search is also wonderful. When correcting text from (say) a hard-copy simply do [M]S and start typing the first few words of the sentence before the edit point. Magically Emacs will take you there.

    This is also very useful for moving around in documents. Simply enter "??" or some other simple placemarker move around, then do [M]S?? and you'll fly back to where you were.

    For formatting "paragraphs" [M]Q is the way forward. Quite simply no other editor I have come across has a better understanding of the 'right' behaviour for this.

    If you have some text that looks like this (n.b. _ indicates space)

    ____Some text that is on a line that we wish to wrap around so that the new line starts aligned to the first line. Ordinarily there is no sensible way of doing this bar tab stops, however if you 'do a meta q' it will magically align this paragraph.

    Then after a [M]q (fill-paragraph) you will get

    ____Some text that is on a line that we wish to wrap around so that
    ____the new line starts aligned to the first line. Ordinarilly there
    ____is no sensible way of doing this bar tab stops, however if you 'do
    ____a meta q' it will magically align this paragraph.

    So that the paragraph is left aligned to the first line. Finally, as others have said regexp replace and various other packages (e.g. AucTeX) are unparalleled!

    --
    Be nice to people on the way up. You will meet them again on your way down!
  47. Rectangle Cut and Paste by rockmuelle · · Score: 4, Informative

    Working with rectangular regions is a breeze in emacs (very useful for quickly swapping columns in csv-type files):

    Set the mark at the upper left of the rectangle... move the cursor the lower right...

    Kill rectangle: c-x r k

    Move somewhere else...

    Yank rectangle: c-x r y

    There are some other rectangle commands, but these are probably the two most useful "unknown" emacs commands I've come across.

    -Chris

  48. Re:Favorite Acronym by Simon+Brooke · · Score: 2, Informative

    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.

    Back in the early nineties, I had an Acorn R140 with 4Mb of core; it ran RISC iX, which was basically BSD 4.2. It could just about run X11; and it could happily run a full Emacs development session (but not under X11). Pretty soon after that I got an R280, which had 8Mb of core; and that ran Emacs under X11 really nicely...

    It's a long time since Emacs has really been slow, but the jokes have long memories.

    --
    I'm old enough to remember when discussions on Slashdot were well informed.
  49. Browsing Code: ecb-mode and etags by jonaskoelker · · Score: 2, Informative

    Whenever you download a bunch of code and want to dip your feet in it, it helps getting a good overview.

    To that end, ecb-mode can be greatly helpful. It displays navigable directory trees, a list of all symbols defined in your current file, a list of recently visited files, and a compile window. Double-click anything to jump to it, quite nice to use. The symbol list is really neat; I've thrown C, python and makefiles at it, much to my satisfaction. Haskell support is a bit rudimentary, but still very useful. It says it handles perl and TeX specially [they can't be parsed without being partially executed]. I don't know how well.

    If you just want to follow symbols around, use etags [use it anyways]. Run etags in your source root (zsh% etags **/*.[ch]), cursor-over a symbol, press M-. to jump to it.

  50. Re:Please Don't Stop by Falkkin · · Score: 3, Insightful

    Yeah, given that the *nix thread had over 2000 comments, I'd say there's a significant demand for more of these sorts of posts.

    My only regret is that I wish they'd spaced out the articles a bit, so that I had some time to digest the tricks in one article before reading the next one -- I find that if I add too many tricks to my toolbox at once I tend to forget about some of them. I guess I should just re-read the articles in another month or so. (Also an indication that these are quality articles -- there's not many discussion threads on Slashdot that I'd even consider going back and re-reading later.)

  51. The best recent package for (X)Emacs: org-mode. by hardaker · · Score: 2, Interesting

    By far one of the best enhancement packages to come out for (X)Emacs in a long time is org-mode. It's a feature-full organization and agenda system that all operates on plain text files that are easy to read and write.

    --
    The next site to slashdot will be ready soon, but subscribers can beat the rush and start slashdotting it early!
  52. Re:Favorite Acronym by 0xABADC0DA · · Score: 4, Funny

    It's a long time since Emacs has really been slow, but the jokes have long memories.

    Performance jokes are never garbage collected -- it would take too many cycles.
    Performance jokes are never garbage collected -- there's always a weak reference to them.

    I'll be here all week... or until tuesday if the alternate pickup schedule is in effect due to holiday or inclement weather.

  53. Re:Questions for Emacs People by An+ominous+Cow+art · · Score: 2, Informative

    The problem was, there was some key combination I was hitting on accident (probably since I am used to nano keybindings) that was causing me to delete large chunks of my document (usually everything above my current view). I didn't realize it, then I would save and have to restore the file from backup. This happened several times. I think it was happening as I was saving, but could never trace back my error.

    My guess would be that you were pressing ctrl-w, "kill-region", which removes everything between your cursor and the 'mark', and places it in the kill buffer. As with ctrl-k, pressing ctrl-y will 'yank' it out and insert it (insert juvenile jokes here :-)).

  54. Mod me everything! by hardaker · · Score: 4, Funny

    Useful(Stupid) things to say to get modded Insightful

    • Emacs rocks!

    Useful(Stupid) things to say to get modded Interesting

    • Escape-: (message "Emacs rocks")

    Useful(Stupid) things to say to get modded Funny

    • Emacs: Escape Meta Alt Control Shift

    Useful(Stupid) things to say to get modded Troll

    • Emacs is better than vi

    Useful(Stupid) things to say to get modded Redundant

    • Emacs is better than vi

    Useful(Stupid) things to say to get modded Flamebate

    • Emacs is better than vi (really... Trolls are just flamers with green skin)

    Useful(Stupid) things to say to get modded Overrated

    • Emacs rocks!

    Useful(Stupid) things to say to get modded Stupid

    • What's emacs anyway?

    Useful(Stupid) things to say to get modded Useful

    • The its-all-text firefox plugin lets you edit slashdot posts in emacs
    --
    The next site to slashdot will be ready soon, but subscribers can beat the rush and start slashdotting it early!
  55. calc and pictures by porpnorber · · Score: 2, Interesting

    Much goodness has been mentioned here, but not the optional emacs-calc package (does vi do calculus? I think not). Plus picture-mode, great for drawing little boxes and, surprise surprise, putting the row of backslashes down the right edge of newly macrofied code blocks (M-x picture-mode C-c ., set typing direction to vertically downwards).

    1. Re:calc and pictures by martinw89 · · Score: 2, Informative

      (does vi do calculus? I think not).

      No, but it does edit files pretty well.

  56. Re:Please Don't Stop by Mikkeles · · Score: 4, Funny

    '... is there any reason the VIM story ran first than the Emacs one?'

    Emacs was still loading when it came time to run the story.

    --
    Great minds think alike; fools seldom differ.
  57. Re:One reason why VI is better... by squiggleslash · · Score: 2, Interesting

    Plus for maximum fun, thinking you're in insert mode because you slipped and hit the wrong key, and actually finding you're in command mode and have just made about 452 different random changes to your document with no idea of what has happened or how to fix it...

    --
    You are not alone. This is not normal. None of this is normal.
  58. emacs replies... by PPH · · Score: 4, Funny

    What are your favorite tricks?

    Why do you say what are my favorite tricks?

    --
    Have gnu, will travel.
  59. Re:vi is for building emacs by i.of.the.storm · · Score: 2, Interesting

    Haha, I really don't understand why vi doesn't have anything helpful at all when you start it up. Emacs' tutorial is so nice and helpful, whereas every time I start vi I have that same experience and just keyboard mash until I manage to quit. I admit that I haven't spent much time trying to learn vi, and only really started using emacs this semester (first semester of college) but if I'm ever on a system that doesn't have emacs nano is better since I can actually figure out how to save and quit without reading documentation. I think that has to be one of the tenets of good UI design; if it isn't completely obvious how to operate a program, it should at least be obvious how to get help within the program. Once I'm in vi and don't know anything knowing to check the manpage isn't going to be much help. I picked up some basic knowledge from the vi thread here but sheesh, that kind of stuff should be readily available inside the program.

    --
    All your base are belong to Wii.
  60. Re:Please Don't Stop by DiegoBravo · · Score: 5, Funny

    So by the next week we may the OpenOffice tricks?

  61. Compiling over ssh by hmckee · · Score: 3, Interesting

    Plus you can compile over ssh.

    It's nice to be able to compile a local directory with M-x compile, then you can jump to errors in the offending file from the *compilation* window.

    You can also set to do remote compile from emacs by putting something similar to this in your .emacs:

    ;; remote compile support
    (setq remote-compile-host "hostname")
    (setq remote-shell-program "/usr/bin/ssh")
    (setq default-directory "/home/username/compileDir")

    No you can compile on the remote host AND bring up offending files from the compile output window with the click of a button.

  62. Re:Notepad tricks by Haeleth · · Score: 2, Interesting

    Notepad has precisely one useful trick, documented here.

  63. Re:iso-accents-mode by Haeleth · · Score: 2, Interesting

    This is the easiest way I know to type accented characters on a US keyboard.

    Even easier: set one of your keys up as Compose (also known as Multi_key). Then you can type accented characters in any program, not just Emacs.

  64. Re:The EMACS equivalent of "." by Haeleth · · Score: 2, Interesting

    "C-x z". Then subsequent presses of "z" repeat the same command again.

    (You could have found that out for yourself by typing "C-h w repeat"...)

  65. Re:Young people being led astray? by Haeleth · · Score: 2, Interesting

    What I find tragic is that people actually do say "it's tragic that we're still using the same tools as we used 20 years ago".

    Why wouldn't we be? We're pretty much the same people as we were 20 years ago. We still speak the same languages, wear the same clothes, drive vehicles that are only cosmetically different, perform very similar jobs. Sure, our computers are a bit faster, but there's no need to fundamentally change your interface just because there are more transistors behind it.

  66. Re:vi is for building emacs by StandardDeviant · · Score: 2, Informative

    Solaris, it's been said, has a great kernel and an utterly shit userland (i.e. the tools you actually interact with). I can almost guarantee you that at some point the admins of your system have gotten pissed off at the Sun-shipped utils (from hell's heart, sun tar, I stab at thee) and have installed some variety of 3rd-party-freeware utilities on the system (either Sun's freeware, Sun Freeware [different], or Blastwave freeware come to mind). You might try looking, if you haven't yet, in /opt and /usr/local to see if bin dirs exist under there somewhere as these are common locations for these packages. If so, adding them into your shell's $PATH will make interactive use a lot more pleasant.

  67. Re:Wanted: su for a buffer by dhTardis · · Score: 2, Informative

    Tramp will also let you use sudo or su to edit your files without SSH: C-x C-f /su::/etc/motd, for example.

  68. Re:vi is for building emacs by i.of.the.storm · · Score: 2, Funny

    I was talking about vi, I didn't know about vim to be honest. On Linux on my computer vi is aliased to vim but not on our Solaris servers at Berkeley.

    Also, a fun related quote from one of the professors here, Paul Hilfinger:

    In the interests of truth, beauty, and justice -- and to undo, in some small part, the damage Berkeley has done by foisting vi on an already-unhappy world -- Emacs will be the official CS61A text editor this semester

    --
    All your base are belong to Wii.