Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Deus Rex
Mar 5, 2005

Is there some way I can assign the system clipboard to a register on OS X? Vim has a nice feature where any interactions with the system clipboard go through the "*" register, so you won't clobber your system clipboard with any Vim-specific editing unless you explicitly ask to do so.

Adbot
ADBOT LOVES YOU

wooger
Apr 16, 2005

YOU RESENT?
I use emacs evil. I know how to define and vim style macros, but I've not been able work out the syntax to save them in my init.el between sessions.

Any suggestions for the best way to do this, so I can call the macros with @m or similar?

pgroce
Oct 24, 2002

Deus Rex posted:

Is there some way I can assign the system clipboard to a register on OS X? Vim has a nice feature where any interactions with the system clipboard go through the "*" register, so you won't clobber your system clipboard with any Vim-specific editing unless you explicitly ask to do so.

I haven't tested this at all, but you should be able to disable the default behavior of putting all the Emacs kills into the clipboard (OS X calls it the pasteboard apparently, news to me) by advising the ns-set-pasteboard function and writing some wrapper functions.

The following tells Emacs to only copy data to OS X's system clipboard if enable-copy-to-clipboard is set to something non-nil.

Lisp code:
(defcustom enable-copy-to-clipboard nil
  "If non-nil, copy data killed in Emacs to clipboard.")

(defadvice ns-set-pasteboard (around adv-selective-copying)
  "Only copy to OS X pasteboard when `enable-copy-to-clipboard'
  is nil."
  (when (equal enable-copy-to-clipboard nil)
    ad-do-it))
From here, you could go in a few directions. You could leave it off forever and never move data to the OS X clipboard. Or you could leave enable-copy-to-clipboard off all the time and bind keys to some special commands that copy to the clipboard. E.g.:

Lisp code:
(defun kill-ring-save-with-pasteboard (beg end)
  "Like `kill-ring-save' but enable OS X pasteboard."
  (let ((enable-copy-to-clipboard t))
    (kill-ring-save beg end)))

(global-set-key (kbd "C-!") 'kill-ring-save-with-pasteboard)
(That's a terrible keybind, but you get the idea.)

Personally, if I wanted this (I don't, but hey, it's your thing), I'd set up a key to toggle between using/not using the system clipboard, and disable it when I was interested in moving data around.

Lisp code:
(defun toggle-copy-to-clipboard ()
  "Turn on/off copying to OS X clipboard"
  (interactive)
  (if enable-copy-to-clipboard
      (progn (setq enable-copy-to-clipboard nil)
             (message "copy to clipboard disabled"))
    (progn (setq enable-copy-to-clipboard t)
           (message "copy to clipboard enabled"))))
I'm not sure how you could disable Emacs reading from the OS X clipboard and, say, clobbering itself because you copied a link in Safari. OTOH, with Emacs you have the kill-ring, so nothing's lost in that case.

I hope I didn't overthink this too much. I'm sure you were looking for a snippet that would just do the job for you, but nothing like that comes to mind. :)


wooger posted:

I use emacs evil. I know how to define and vim style macros, but I've not been able work out the syntax to save them in my init.el between sessions.

Any suggestions for the best way to do this, so I can call the macros with @m or similar?

I don't know anything about evil, but as a guy who used vim exclusively for 10 years, I'm interested in seeing the answer.

Xik
Mar 10, 2011

Dinosaur Gum
Are there any decent videos/screencasts out there by emacs masters that are just doing their thing and maybe explaining some of the features they use?

The Peepcode Play by Plays are the type of thing I'm talking about. I have the one with Jim Weirich and it was fun watching him work and chat about some of the emacs features he uses. There may have been other Play by Plays where they used emacs but I obviously can't go there anymore.

Does that type of content exist?

Deus Rex
Mar 5, 2005

Emacsrocks and the companion series Extending Emacs are both great. Magnar's enthusiasm is infectious.

https://www.youtube.com/watch?v=D6h5dFyyUX0

Xik
Mar 10, 2011

Dinosaur Gum
Thanks, they are pretty great! I watched the first few and plan to go through the rest.

Is he not creating any more? The last video was 5 months ago and the last "episode" was a year ago.

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace
Ok, when pressing page-up or page-down the cursor moves as I scroll through the file. But when I get to the top or bottom of the file, the cursor doesn't go all the way to the top or bottom. It just chills in the middle of the screen. What can I do about this?

Also! holy crap I spent a few minutes and setup multiple cursors mode and now I can use emacs like how I use Sublime Text! :hellyeah: It's actually hard for me to be productive in emacs because I keep getting excited about some package or mode and spend time reading about it instead of working. M-x package-list-packages is really fun to poke around in.

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen

PlesantDilemma posted:

Ok, when pressing page-up or page-down the cursor moves as I scroll through the file. But when I get to the top or bottom of the file, the cursor doesn't go all the way to the top or bottom. It just chills in the middle of the screen. What can I do about this?

Customize the scroll-error-top-bottom variable to t.

PlesantDilemma posted:

Also! holy crap I spent a few minutes and setup multiple cursors mode and now I can use emacs like how I use Sublime Text! :hellyeah: It's actually hard for me to be productive in emacs because I keep getting excited about some package or mode and spend time reading about it instead of working. M-x package-list-packages is really fun to poke around in.

Don't sweat it: your personal configuration will self-optimise to a point of stable comfort after a few decades.

ynohtna fucked around with this message at 20:42 on May 12, 2014

dobbymoodge
Mar 8, 2005

I know Xah is a controversial turd sometimes, but he seems to be in real trouble right now: http://ergoemacs.org/misc/xah_as_good_as_dead.html

He's a bit of a wretched cave troll, but he does dedicate a great deal of his energy towards helping people learn Emacs (and other things.) I know that I would probably not have been able to integrate Emacs into my workflow if I hadn't come across his tutorials early in my newbie phase.

Help him if you feel compelled, though I'm not sure how much good buying one of his tutorials will do him (or you). Just thought I would bring this up here, since you folks will have probably heard of him.

Edit: In case you do feel like helping him, pay attention to this detail towards the bottom of the linked page:

Probably mentally ill troll Xah Lee posted:

i won't actually be able to draw money from paypal, due to bank/IRS problem. So

better, send your check to:

Huynh Kang at huynh.kang facebook or huynh-kang linkedin
professor Richard Palais, home page at University of California Irvine http://vmm.math.uci.edu/, Wikipedia Richard Palais, richard-palais on linkedin
they are my friends and have been helping me financially recently.

dobbymoodge fucked around with this message at 15:24 on May 16, 2014

Pham Nuwen
Oct 30, 2010



dobbymoodge posted:

I know Xah is a controversial turd sometimes, but he seems to be in real trouble right now: http://ergoemacs.org/misc/xah_as_good_as_dead.html

He's a bit of a wretched cave troll, but he does dedicate a great deal of his energy towards helping people learn Emacs (and other things.) I know that I would probably not have been able to integrate Emacs into my workflow if I hadn't come across his tutorials early in my newbie phase.

Help him if you feel compelled, though I'm not sure how much good buying one of his tutorials will do him (or you). Just thought I would bring this up here, since you folks will have probably heard of him.

Edit: In case you do feel like helping him, pay attention to this detail towards the bottom of the linked page:

So I remember several years ago he was living out of his car because he was a miserable turd who was far too brilliant to hold down a regular job with the rest of us plebs. Apparently he got some money at some point (sold the car?) and has been living, by himself, in a $1500/month apartment, despite no longer having an income source. Now surely even before the IRS took the money he owed, he knew he wouldn't be able to pay the next month's rent, but he still waited until he was absolutely penniless to actually get a goddamn job. Now he thinks that because he actually has a full-time job, there's just no possible time in the remaining 15 hours of the day to interview for something better?

He's been a irredeemable shitlord since I first encountered him almost a decade ago, and it's apparently taken him this long to realize you don't get paid to call people stupid in newsgroups.

I do like that he's not too distraught to download porn... and leave the download thingy up in his Chrome screenshot so we can all go to imgur and see his preferences.

Edit: If people give him enough money to pay rent (via his friends, does that make them accessories to tax evasion), I'll bet he pays rent and quits his dishwashing job. He should perhaps consider getting a job that's not in computing, since over a decade of being a very vocal shitbird on the Internet means a LOT of interviewers are going to say, "Xah Lee? Hah, gently caress that guy." I know I would.

Pham Nuwen fucked around with this message at 16:36 on May 16, 2014

dobbymoodge
Mar 8, 2005

Pham Nuwen posted:

So I remember several years ago he was living out of his car because he was a miserable turd who was far too brilliant to hold down a regular job with the rest of us plebs. Apparently he got some money at some point (sold the car?) and has been living, by himself, in a $1500/month apartment, despite no longer having an income source. Now surely even before the IRS took the money he owed, he knew he wouldn't be able to pay the next month's rent, but he still waited until he was absolutely penniless to actually get a goddamn job. Now he thinks that because he actually has a full-time job, there's just no possible time in the remaining 15 hours of the day to interview for something better?

He's been a irredeemable shitlord since I first encountered him almost a decade ago, and it's apparently taken him this long to realize you don't get paid to call people stupid in newsgroups.

Looking at his history, I think it's apparent that he probably has some serious unaddressed mental or emotional problems. You're right, his behavior is pretty narcissistic and irresponsible, and I don't think tossing cash at him is going to change anything. Even if he had the self awareness to realize this, it wouldn't help. He's saying "I need cash for rent" but he should really be saying "I need a minimum of 3 years therapy, probably some meds, an employment counselor, and weekly visits from a nutritionist." You can't get that over paypal.

I didn't make my last post in order to guilt people into donating to him; the guy is a grade-A bridge-burner, I'd be surprised if he gets enough donations to cover rent. That said, Emacs users are probably the only people on Earth who have any reason to care about his well-being, and he is a human being who deserves some compassion. I doubt anyone here really has the resources to get this guy the help and support that he truly needs. If there is some social worker who lives in the bay area, uses Emacs, is a goon, has nothing better to do and feels like helping him out, I'd feel pretty lovely if I only discovered that after Xah's bloated carcass is fished out of a storm drain.

I'd be surprised if he didn't have scurvy or pellagra or something, homeboy has been eating just oats and noodles for 3+ years now? In his youtube interview with Sacha Chua his gums look pretty recessed, so who knows what else is going on.

Pham Nuwen posted:

I do like that he's not too distraught to download porn... and leave the download thingy up in his Chrome screenshot so we can all go to imgur and see his preferences.

This is pretty hilarious.

Pham Nuwen posted:

Edit: If people give him enough money to pay rent (via his friends, does that make them accessories to tax evasion), I'll bet he pays rent and quits his dishwashing job. He should perhaps consider getting a job that's not in computing, since over a decade of being a very vocal shitbird on the Internet means a LOT of interviewers are going to say, "Xah Lee? Hah, gently caress that guy." I know I would.

100% with you on this; his prospects are probably whatever upwards mobility he has with his dishwashing gig, even if he does get all the help and rehabilitation in the world.

weird
Jun 4, 2012

by zen death robot

dobbymoodge posted:

I didn't make my last post in order to guilt people into donating to him; the guy is a grade-A bridge-burner, I'd be surprised if he gets enough donations to cover rent. That said, Emacs users are probably the only people on Earth who have any reason to care about his well-being, and he is a human being who deserves some compassion. I doubt anyone here really has the resources to get this guy the help and support that he truly needs. If there is some social worker who lives in the bay area, uses Emacs, is a goon, has nothing better to do and feels like helping him out, I'd feel pretty lovely if I only discovered that after Xah's bloated carcass is fished out of a storm drain.

lmbo

shrughes
Oct 11, 2008

(call/cc call/cc)
I've met him in person at a meetup, he's a nice guy as far as I can tell.

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace
Hey thread, Whats your flow to get tabs to work correctly? I'm in the javascript mode that comes with Emacs 24.3.1. I load a file that uses tabs for indent, and tabs are rendered as 8 spaces. When I press the tab key, I get 4 spaces inserted. I know every mode can set it up differently. What are the usual functions/variables that need to be tweaked to get tabs the way you like? My goal is to edit this javascript file and press tab and get a tab character that renders as 4 spaces.

Pham Nuwen
Oct 30, 2010



PlesantDilemma posted:

Hey thread, Whats your flow to get tabs to work correctly? I'm in the javascript mode that comes with Emacs 24.3.1. I load a file that uses tabs for indent, and tabs are rendered as 8 spaces. When I press the tab key, I get 4 spaces inserted. I know every mode can set it up differently. What are the usual functions/variables that need to be tweaked to get tabs the way you like? My goal is to edit this javascript file and press tab and get a tab character that renders as 4 spaces.

The first and perhaps most difficult thing will be convincing emacs to insert actual tab characters. I have managed it and will share my elisp when I'm back at my desk.

Edit: Ok here's how I set up my C mode, you should be able to use something similar:

code:
;; RMS's retarded C style strikes again
(defun linux-c-mode ()
  "C mode with adjusted defaults for use with the Linux kernel."
  (interactive)
  (c-set-style "k&r")
  (setq tab-width 8)
  (define-key c-mode-map (kbd "TAB") 'self-insert-command)
  (setq indent-tabs-mode t)
  (setq c-basic-offset 8))
(add-hook 'c-mode-hook 'linux-c-mode)
You'll want to define a hook for javascript-mode or whatever.

Theoretically you shouldn't have to do that define-key thing, but sometimes emacs loving Lies. They claim that (setq indent-tabs-mode t) would insert tabs, but it just didn't seem to do it. This is my scorched-earth approach and it seems to work.

Pham Nuwen fucked around with this message at 23:25 on May 21, 2014

aerique
Jul 16, 2008
I've got this for Python mode:

code:
(add-hook 'python-mode-hook
          (lambda ()
            (when (at-work)
              (setq indent-tabs-mode t
                    show-trailing-whitespace nil
                    tab-width 4))
            (whitespace-mode 1)))

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
I'd also recommend customizing backward-delete-char-untabify-method as nil, so that tabs will not be converted to spaces when you backspace. This may or may not be related to the problems that Pham has. It's a global customization, which is probably for the best. Use the customization UI and don't try to put it in the hook.

Pham Nuwen
Oct 30, 2010



Gazpacho posted:

I'd also recommend customizing backward-delete-char-untabify-method as nil, so that tabs will not be converted to spaces when you backspace. This may or may not be related to the problems that Pham has. It's a global customization, which is probably for the best. Use the customization UI and don't try to put it in the hook.

Oh, yeah, I have that elsewhere in my .emacs too. Good call.

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace
Does every major mode have a hook? I added this to my .emacs

Lisp code:
(defun fn-fix-the-tabs ()
  "Try to make tabs work the way I want :)"
 (interactive)
 (setq indent-tabs-mode t) 
 (setq tab-width 4) 
 (setq c-basic-offset 4)
 (setq tab-stop-list (number-sequence 4 200 4))
 (define-key c-mode-map (kbd "TAB") 'self-insert-command))

(add-hook 'php-mode-hook 'fn-fix-the-tabs)
(add-hook 'javascript-mode-hook 'fn-fix-the-tabs)
But when I open a php or javascript file it does not take effect. If I do M-x fn-fix-the-tabs then it kicks in. Also, do I need (interactive) in there?

Pham Nuwen
Oct 30, 2010



PlesantDilemma posted:

Does every major mode have a hook? I added this to my .emacs

Lisp code:
(defun fn-fix-the-tabs ()
  "Try to make tabs work the way I want :)"
 (interactive)
 (setq indent-tabs-mode t) 
 (setq tab-width 4) 
 (setq c-basic-offset 4)
 (setq tab-stop-list (number-sequence 4 200 4))
 (define-key c-mode-map (kbd "TAB") 'self-insert-command))

(add-hook 'php-mode-hook 'fn-fix-the-tabs)
(add-hook 'javascript-mode-hook 'fn-fix-the-tabs)
But when I open a php or javascript file it does not take effect. If I do M-x fn-fix-the-tabs then it kicks in. Also, do I need (interactive) in there?

I think c-basic-offset might work in all modes, but I'm not sure about the c-mode-map thing for javascript mode.

Also, it looks like the javascript mode is js-mode, so try (add-hook 'js-mode-hook 'fn-fix-the-tabs)

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
Most major modes have a mode hook. css-mode is an example of one that doesn't and I would consider that a bug.

You only need (interactive) in functions that you run from the minibuffer.

vvvv yeah

Gazpacho fucked around with this message at 20:06 on May 22, 2014

Deus Rex
Mar 5, 2005

Gazpacho posted:

You only need (interactive) in functions that you run from the minibuffer.

You need them on anything which is done 'interactively', whether from a keybinding or the minibuffer.

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace

Pham Nuwen posted:

it looks like the javascript mode is js-mode, so try (add-hook 'js-mode-hook 'fn-fix-the-tabs)

This did it for my Js stuff, and the php-mode-hook does work, I didn't realize that it wasn't enabling php-mode when I open a php file, it was still in fundamental haha. I added this and now I'm golden:

Lisp code:
(add-to-list 'auto-mode-alist '("\\.php\\'" . php-mode))
Emacs is pretty great and this thread is also great :)

Xik
Mar 10, 2011

Dinosaur Gum
I have the whitespace-style "lines-tail" option on so it highlights when I columns exceed X characters. I like it when I'm writing code, but it's super annoying when I'm in my personal org-mode files, especially since I use tables a whole bunch.

I've had to turn the option off for now, but is there a way I can have it on all the time except when in org-mode?

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen

Xik posted:

I have the whitespace-style "lines-tail" option on so it highlights when I columns exceed X characters. I like it when I'm writing code, but it's super annoying when I'm in my personal org-mode files, especially since I use tables a whole bunch.

I've had to turn the option off for now, but is there a way I can have it on all the time except when in org-mode?

org-mode hook containing something like (set (make-local-variable 'whitespace-style) (remove 'lines-tail whitespace-style)) ?

pgroce
Oct 24, 2002

ynohtna posted:

org-mode hook containing something like (set (make-local-variable 'whitespace-style) (remove 'lines-tail whitespace-style)) ?

Beaten, but just for completeness:

Lisp code:
(add-hook 'org-mode-hook 
          (lambda () 
            (set (make-local-variable 'whitespace-style) 
                 (remove 'lines-tail whitespace-style))))
Or you could disable whitespace-mode in org-mode buffers entirely:

Lisp code:
(add-hook 'org-mode-hook (lambda () (whitespace-mode 0)))
I'm always happy to see new posts in this thread. :3:

Xik
Mar 10, 2011

Dinosaur Gum

pgroce posted:

Beaten, but just for completeness:

Lisp code:
(add-hook 'org-mode-hook 
          (lambda () 
            (set (make-local-variable 'whitespace-style) 
                 (remove 'lines-tail whitespace-style))))

Awesome, thank you both, that did it!

I really should learn (emacs) lisp at some point, it's just so drat foreign compared to what I already know.

fishbacon
Nov 4, 2009
wonderful yet strange smell

Xik posted:

Awesome, thank you both, that did it!

I really should learn (emacs) lisp at some point, it's just so drat foreign compared to what I already know.

Learning the basics has done a lot of good for me, it makes it far easier to figure out what a thing is doing, especially these days when I use Company which has almost no documentation.

I recently had to do a small project in C++ for Uni, it turns out that clang is much cooler than I thought and flycheck uses it to make C++ almost fun to write. In fact I am amazed at how good flycheck is.

Through looking for documentation for Company I found this emacs config:
http://steckerhalter.co.vu/steckemacs.html

It contains a bunch of nice packages, like quelpa which manages emacs packages from a bunch of different sources, it is nicely formatted, and well explained.

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace
Ok I broke my emacs and now I'm sad. Emacs 24.3.1 on Ubuntu. I used the package manger to install the Sublime Text package, now when I start emacs I get some startup errors. Emacs runs but it doesn't load my .emacs file and I can't use the ESC button. Every time I press ESC to do a M-x the minibuff says "Cannot open load file: /yasnippet" Omg I can't do M-x that's like my main thing.

How do I uninstall the sublime package I installed?

Emacs told me to run emacs --debug-init and It points to yasnippet being where the problem is. Or at least that's where stuff breaks, the real problem could be elsewhere.

I see both a yasnippet and sublime folder under .emacs.d/elpa/ should I delete those folders?

aerique
Jul 16, 2008
I don't use a package manager for Emacs so take this for what it's worth.

PlesantDilemma posted:

I see both a yasnippet and sublime folder under .emacs.d/elpa/ should I delete those folders?

You could start with just moving / renaming the folder and see how that goes. There's probably some init file somewhere loading those so Emacs will still complain it can't find sublime and yasnippet.

I have no idea where the package manager stores its configuration but doing a
code:
egrep -Iir sublime\|yasnippet .
in the .emacs.d directory or your home directory should give you some pointers.

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace
Thanks for the tips Aerique. Renaming the two folders was enough to get everything working again. Whew.

Hey, does anyone use keybindings other than M-w and C-w for copy/cut ? I don't like M-w for copy, but I don't know what other keybinding to use. I'm afraid I'll overwrite something useful that I just don't know about yet.

Deus Rex
Mar 5, 2005

I use C-w for backward-kill-word, as in Readline, and C-x C-k for killing a region. I find myself needing to kill a word way more often than a region, and this way I can minimize reaches for backspace.

aerique
Jul 16, 2008

PlesantDilemma posted:

Hey, does anyone use keybindings other than M-w and C-w for copy/cut ? I don't like M-w for copy, but I don't know what other keybinding to use. I'm afraid I'll overwrite something useful that I just don't know about yet.

Don't be afraid of that. Emacs is meant to be customized.

I've been using a evil-mode for a couple of years now which gives me Vim-like behavior, before that I had extensive custom keybindings of my own. The last iteration of which converged to what is considered default for standard Windows and Linux apps. So C-z, C-x, C-c, C-v for undo, cut, copy and paste. C-a for selected all. C-PgUp and -PgDn for cycling through tabs, etc. etc. It was nice but I had used Vim in the past and preferred that.

Before that I had really my own custom bindings which were pretty optimal and nice but too different from other apps which irked me.

pgroce
Oct 24, 2002

aerique posted:

Don't be afraid of that. Emacs is meant to be customized.

Amen. And even stock Emacs is sensitive to the fact that the cut and paste commands are idiosyncratic; the Mac builds by default map Command-x/c/v to cut/copy/paste. (I unbind them because I use Command as Meta, and also I'm cranky and hate change. (Friends don't let friends use cua-mode.))


PlesantDilemma posted:

I'm afraid I'll overwrite something useful that I just don't know about yet.

The most helpful command for figuring out what key maps to what (and what you might be overwriting) is describe-key (bound to C-h k). It will also tell you if a key is not bound.

If you're still concerned about keeping the default keybinds around (a lot of them are quite useful, and it's nice not to be completely lost when you sit down at someone else's Emacs :) ), here's another tip. In addition to Control and Meta, Emacs also uses the Super and Hyper modifiers, but because modern keyboards don't have Super and Hyper keys, there aren't many commands mapped to use those modifiers, and the ones that remain are, shall we say, non-essential. If you have a seldom-used key on your keyboard (I use the right control key), you can bind it to one of those seldom-used modifiers (I use Super) and do whatever the hell you want.

How you do this is platform-specific. Noted I-guess-not-homeless-guy Xah Lee explains how to use Super and Hyper on Windows and Mac. (All the mac-prefixed variables he mentions are now aliases for variables prefixed with ns- because RMS is a big nerd. You can use either, but I guess mac- might go away someday. Maybe.)

Presumably one does this on Linux through either X keymaps or terminal escape code voodoo, depending on whether you're running Emacs on the terminal or in a GUI window. I haven't dealt with that in years, hopefully someone knowledgeable can chime in.

aerique
Jul 16, 2008
A reason to get familiar with the Emacs defaults would be that the Bash[1] shell uses them as well, but those can be rebound as too.

[1] the readline library actually so the key bindings return in more apps

pgroce
Oct 24, 2002

aerique posted:

A reason to get familiar with the Emacs defaults would be that the Bash[1] shell uses them as well, but those can be rebound as too.

[1] the readline library actually so the key bindings return in more apps

Also the standard GUI widgets on OS X!

Hollow Talk
Feb 2, 2014

pgroce posted:

Amen. And even stock Emacs is sensitive to the fact that the cut and paste commands are idiosyncratic; the Mac builds by default map Command-x/c/v to cut/copy/paste. (I unbind them because I use Command as Meta, and also I'm cranky and hate change. (Friends don't let friends use cua-mode.))


The most helpful command for figuring out what key maps to what (and what you might be overwriting) is describe-key (bound to C-h k). It will also tell you if a key is not bound.

If you're still concerned about keeping the default keybinds around (a lot of them are quite useful, and it's nice not to be completely lost when you sit down at someone else's Emacs :) ), here's another tip. In addition to Control and Meta, Emacs also uses the Super and Hyper modifiers, but because modern keyboards don't have Super and Hyper keys, there aren't many commands mapped to use those modifiers, and the ones that remain are, shall we say, non-essential. If you have a seldom-used key on your keyboard (I use the right control key), you can bind it to one of those seldom-used modifiers (I use Super) and do whatever the hell you want.

How you do this is platform-specific. Noted I-guess-not-homeless-guy Xah Lee explains how to use Super and Hyper on Windows and Mac. (All the mac-prefixed variables he mentions are now aliases for variables prefixed with ns- because RMS is a big nerd. You can use either, but I guess mac- might go away someday. Maybe.)

Presumably one does this on Linux through either X keymaps or terminal escape code voodoo, depending on whether you're running Emacs on the terminal or in a GUI window. I haven't dealt with that in years, hopefully someone knowledgeable can chime in.

On Linux, I have Hyper mapped to Capslock, though I don't use it in Emacs but for i3wm as my general mod-key there. It's a bit of a pain to do though; I used Xmodmap (and ~/.Xmodmap as the config file for it) to unbind the modifiers, set they specific keys via keycodes, then reassigned the modifiers, which ends up looking like this:

code:
clear Lock
clear Mod1
clear Mod3
clear Mod4
keycode 64 = Alt_L
keycode 66 = Hyper_L
keycode 135 = Multi_key
add Mod1 = Alt_L
add Mod3 = Hyper_L Hyper_R
add Mod4 = Meta_L Meta_R
That said, I'm not sure whether your keycodes are necessarily going to be the same, so that's something you'd have to try. Also be careful with unbinding keys, because you can do stupid things. An alternative you can try is modifying ~/.Xkbmap, though I've had mixed success with this.

Hollow Talk fucked around with this message at 01:33 on Jul 3, 2014

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace
So I used M-x upcase-region and got a warning about it often confusing new users. What's the story on that? Is it doing something besides just making all the letters capitol? I was surprised by the warning.

Hollow Talk
Feb 2, 2014

PlesantDilemma posted:

So I used M-x upcase-region and got a warning about it often confusing new users. What's the story on that? Is it doing something besides just making all the letters capitol? I was surprised by the warning.

Essentially, there are some functions which the average (or new) user usually doesn't use or that would confuse them. One such example is the narrowing down of a buffer which might sometimes be useful but to a new user might seem like most of their document just vanished. M-x upcase-region is probably another such function, because it won't be used that often, hence the warning. It's really just a way to keep people from activating something unknowingly yet still giving people who do need the functionality a way to do so. When the message pops up, you will also get presented with a number of shortcuts in the minibuffer, which are essentially "use despite warning" or "cancel", but also "unlock for future use", which means you won't see the warning again as a variable is written to your profile file.

Essentially, upcase-region will do exactly what it says, it's just that what it does is rarely what most people would want. If you need to use it, just do, there aren't any other undocumented consequences!

Adbot
ADBOT LOVES YOU

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
On top of what Hollow Talk correctly states, upcase-region is also mapped by default to a key sequence that a new user may invoke accidentally before they have learnt the core of how Emacs works and - vitally - how to invoke the essential undo operation.

  • Locked thread