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
BusError
Jan 4, 2005

stupid babies need the most attention

Atlas Air posted:

Every time I compile latex, I have to save the file, press enter etc. Is there a how to make emacs do all this automatically?
It would be fantastic if it could C-c ` automatically if there were any errors aswell. (` is a bit of a hassle of danish keyboards)

I might not be understanding your question quite right, but I make pretty heavy use of 'shell-command for something like this. I have a little function called "command-runner" that does this:

code:
(defun command-runner ()
  (interactive)
  (save-buffer)
  (shell-command my-current-command))
I can set the variable "my-current-command" to something like "cd project_folder; latex myfile; open myfile.pdf;" and then when I hit the keybinding for this function (C-\ in my case) it saves the file, compiles it, and opens it. And I get compile errors in the mini-window at the bottom of the screen.

Adbot
ADBOT LOVES YOU

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
Everything you asked about is customizable in the compile command. The customization variables affect the whole session, so I don't recommend setting them permanently in .emacs. However you can define commands to toggle them as needed.
Lisp code:
(defun enable-quick-compile ()
  (interactive)
  (setq compilation-ask-about-save nil)
  (setq compilation-read-command nil)
  (setq compilation-auto-jump-to-first-error t))

(defun disable-quick-compile ()
  (interactive)
  (setq compilation-ask-about-save t)
  (setq compilation-read-command t)
  (setq compilation-auto-jump-to-first-error nil))
You will have to run the compile command once the hard way, to get a prompt for a command line.

pgroce
Oct 24, 2002
You can also set them as file local variables, if you're mainly running compile from one file.

Atlas Air
Apr 8, 2010

BusError posted:

I might not be understanding your question quite right, but I make pretty heavy use of 'shell-command for something like this. I have a little function called "command-runner" that does this:

code:
(defun command-runner ()
  (interactive)
  (save-buffer)
  (shell-command my-current-command))
I can set the variable "my-current-command" to something like "cd project_folder; latex myfile; open myfile.pdf;" and then when I hit the keybinding for this function (C-\ in my case) it saves the file, compiles it, and opens it. And I get compile errors in the mini-window at the bottom of the screen.

Very cool! How do you set the variable? (I'm very new to emacs)

BusError
Jan 4, 2005

stupid babies need the most attention

Atlas Air posted:

Very cool! How do you set the variable? (I'm very new to emacs)

There is most likely a better way to do this, but here's what I do:
code:
(defun set-current-command (new-com)
  (interactive "sSet command: ")
  (setq current-command new-com)
  (message (concat "Set command to " current-command)))

(defcustom current-command
  "echo \"You have to set this.\""
  "the command you want to run")
I give myself the 'set-current-command function, and I defcustom the current-command variable with a default so if I try to run it before I've set it, nothing harmful happens.

Like I said, this may not be the best way of accomplishing this goal, but I use it all the time and it works well for me :)

edit to add: I stole this idea from Gary Bernhardt's Destroy All Software screencasts. He uses Vim, but the technique is pretty similar to this. BTW, if you are a programmer you should totally check out his videos.

BusError fucked around with this message at 19:23 on Mar 31, 2013

fishbacon
Nov 4, 2009
wonderful yet strange smell
I just discovered how powerful YAsnippets can be, I was having to do a lot of repetitive work for Uni (we have a bunch of small hand-ins this semester) and I decided to look into templates, turns out YAsnippets just does cool stuff with fields and elisp code.

I spend like 2 hours today figuring out how to do something, and I ended up actually learning a few things about elisp. I love when a simple challenge ends up brightening my whole day.


Sharing of my *Scratch* hiding technique:
Lisp code:
;; bury *scratch* buffer instead of killing it
(defadvice kill-buffer (around kill-buffer-around-advice activate)
  (let ((buffer-to-kill (ad-get-arg 0)))
    (if (equal buffer-to-kill "*scratch*")
        (bury-buffer)
      ad-do-it)))
It simply moves scratch to the back of the queue whenever I try to kill it, because it is such a great buffer to keep around.

I also fiddled with kbd today, turns out it will return exactly what "C-ø" means so that I don't have to have anything ugly in my emacs file.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Mr. Fish posted:

(bury-buffer)
I think I'll do it this way from now on, except I'll continue putting it in a hook. Hooks are great. Write hooks. Be a hooker.

Lothas
Aug 24, 2012
Iv got a bit of a daft question if anyone has the time to help me out.

Iv just installed Emacs on a windows machine and I'm having trouble compiling C++ programs. As far as I can tell it is something to do with the compiler (make-k, I understand this is for Linux) what I'm struggling with is how to change the compiler that Emacs is using.

In short does anyone know how to change the compiler Emacs uses for C++?

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
Putting (setq compile-command "something or other") in your config changes the default command line, for all languages. It can be customized for particular language modes, and the documentation of the compile-command variable describes how, but this requires detailed elisp coding. In your case you would customize c++-mode-hook instead of c-mode-hook.

Gazpacho fucked around with this message at 21:20 on Apr 4, 2013

Arcsech
Aug 5, 2008
I'm thinking about dumping in the time to learn emacs, but there's something specific I'm looking for. I do a lot of programming in embedded C, and basically I want my editor to do this sort of thing:


But for C. I know the latter comes from CEDET, but is setting that up to work on Windows with a special microcontroller standard library going to make me want to gouge my eyes out?

In an ideal world, it would work with Doxygen comments to supply stuff like in the first screenshot and work with Python too, but I'll take what I can get.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I wrote the auto-complete backend for ropemacs. I don't know the status of it today (some dude on GitHub was going to try to upstream it, but I lost track of that).

auto-complete is fairly complicated and tends to be slow. I'd recommend against using it unless you tweak it properly. It's probably possible to write a CEDET backend for it, but it'd require some elisp knowledge.

BusError
Jan 4, 2005

stupid babies need the most attention
Has anyone messed around with any of the Vim emulation packages in Emacs? I've been wanting to learn more about Vim, both for when I'm on a server with no Emacs and also just to broaden my editing horizons. vi-mode seems to not really have any of the cool stuff I've seen pro Vim users use, so I think that's out. Any experience with stuff like evil?

Catalyst-proof
May 11, 2011

better waste some time with you

BusError posted:

Has anyone messed around with any of the Vim emulation packages in Emacs? I've been wanting to learn more about Vim, both for when I'm on a server with no Emacs and also just to broaden my editing horizons. vi-mode seems to not really have any of the cool stuff I've seen pro Vim users use, so I think that's out. Any experience with stuff like evil?

If I were you I'd seriously just use vim proper. I can't imagine any other way of 'learning more about Vim' would be more effective than that. I'm an rear end in a top hat so I suggest taking a quick—a very quick—look at nvi to understand exactly what vim brings to the table, also people seem to like this StackOverflow answer. See what you made me did? You made me link to StackOverflow. I hope you're loving happy.

EDIT: That's brew install nvi for you Apple freaks. Dunno what the equivalent is on any other OS.

Catalyst-proof fucked around with this message at 22:10 on Apr 8, 2013

BusError
Jan 4, 2005

stupid babies need the most attention

horse mans posted:

If I were you I'd seriously just use vim proper. I can't imagine any other way of 'learning more about Vim' would be more effective than that. I'm an rear end in a top hat so I suggest taking a quick—a very quick—look at nvi to understand exactly what vim brings to the table, also people seem to like this StackOverflow answer. See what you made me did? You made me link to StackOverflow. I hope you're loving happy.

EDIT: That's brew install nvi for you Apple freaks. Dunno what the equivalent is on any other OS.

haha fair enough on the learning through immersion part. I think deep down I realize I should just dive in, I am just dreading how awkward and slow I'll feel at first.

But my question still stands of whether or not anyone's messed with those modes. Beyond just learning vim, I'm curious about the parts they get right and where they fall flat.

wooger
Apr 16, 2005

YOU RESENT?

BusError posted:

Has anyone messed around with any of the Vim emulation packages in Emacs? I've been wanting to learn more about Vim, both for when I'm on a server with no Emacs and also just to broaden my editing horizons. vi-mode seems to not really have any of the cool stuff I've seen pro Vim users use, so I think that's out. Any experience with stuff like evil?

I've used Vim exclusively for the last couple of years, but I just recently switched to emacs after reading about some of the advanced features and modes available.

I use evil all the time, it works perfectly and is well maintained, though you need a couple of other config changes to make it totally feel like vi. I mapped Esc to totally kill any command anywhere, so it's now pretty much identical to Vim when I'm not using one of the fancy modes. All the vim commands I commonly used are emulated with the exact same syntax.

As I use it, it looks like Vim, but with better file and directory management, more features (the regex replace in evil visually shows you the changes as you type the command), and better written extension scripts.

BusError
Jan 4, 2005

stupid babies need the most attention

wooger posted:

I've used Vim exclusively for the last couple of years, but I just recently switched to emacs after reading about some of the advanced features and modes available.

I use evil all the time, it works perfectly and is well maintained, though you need a couple of other config changes to make it totally feel like vi. I mapped Esc to totally kill any command anywhere, so it's now pretty much identical to Vim when I'm not using one of the fancy modes. All the vim commands I commonly used are emulated with the exact same syntax.

As I use it, it looks like Vim, but with better file and directory management, more features (the regex replace in evil visually shows you the changes as you type the command), and better written extension scripts.

Cool, thanks for the report. I may mess around with evil-mode a bit this weekend :)

Catalyst-proof
May 11, 2011

better waste some time with you

orphean posted:

I'm glad I'm not the only one who doesn't care for nxHtml. I have some mental block when trying to use that drat thing. For just multiple mode support without alot of the extra cruft check out MultiWebMode (https://github.com/fgallina/multi-web-mode) Basically to use it you just setup a plist where the label is the name of the mode you want to use and the value is a regex telling it how to recognize the region for that mode. This is all documented. As a plus you can use whatever major-mode you want for each thing easily. Want js2-mode for javascript? Go for it. Want some funky custom mode for css? Sure, why not. Etc.

This is from a hell of a while back, but do you actually use js2-mode with multi-web-mode? Could you let me know where you installed both from and what your configuration looks like? The latest version of js2-mode I have is from 2013, and it still has a comment to the effect of "this does not yet work with multi-mode modes", and when using it I just get a bunch of red-highlighted code and the error 'Unexpected end of file'.

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?
What is the difference between emacs-auto-save-directory and .emacs.d/auto-save-list?

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
The latter is a file that emacs uses to track files that have been auto-saved successfully so they can be recovered following a crash. The former is, I'm guessing, the directory where emacs has been set up to place the actual auto-saved files on your system.

Gazpacho fucked around with this message at 08:30 on Apr 18, 2013

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man
So the other day I upgraded to emacs24 - had to build from source because aptitude is stuck on 23. And yesterday I was doing some TeX editing and realized I didn't have AUCTeX. "Gee", I thought, "maybe I should use this package manager thing that I basically specifically installed emacs24 for." So I did. And then AUCTeX wouldn't work still. And I couldn't find a reason until, while reading the doc, I realized that the "base" .el file, the one you have to load to make it all work, is named texsite.el for some reason. Lo and behold, if you change texsite.el to be auctex.el, the same as the package name, poo poo Just Works.

Am I wrong about that? Did I accidentally fix it some other way? Because if I'm not, why the gently caress don't the auctex folks just name their goddamn file auctex.el so it doesn't break ELPA?

BusError
Jan 4, 2005

stupid babies need the most attention
If anybody is using Org Mode, they just released the next major version (8.0): http://orgmode.org/Changes.html

Unfortunately it looks like the bulk of the changes are to features I didn't really use, although I am kind of excited about the RSS export feature. I've been playing around with static site generators for my blog and haven't really been satisfied, so I might give Org a shot for that purpose next.

Catalyst-proof
May 11, 2011

better waste some time with you
Is there any way to copy a buffer-local variable to another buffer?

EDIT: Nevermind, dumb question.

Catalyst-proof fucked around with this message at 14:51 on Apr 23, 2013

aerique
Jul 16, 2008
So, what completion engines are people running here that they are happy with?

I've been using Helm (was: Anything) for more than a year now and am pretty content with it. I'm also still using auto-complete.el and Slime's own fuzzy completion (because ac-slime was slow as gently caress) and once I have consolidated the latter two into Helm it should all feel a little more consistent.

The one thing I would like is for the Helm buffer to open in the biggest available other-window, but I haven't been able to write a correct elisp function for that.

(Written on mobile so I can't be bothered to check for the correct names and provide URLs, sorry...)

Zombywuf
Mar 29, 2008

aerique posted:

So, what completion engines are people running here that they are happy with?

I just use hippie complete, mostly using dabbrev expand.

Arcsech
Aug 5, 2008
I'm trying to use electric-layout-mode in C, but I can't figure out how to set it up. Here's the documentation:

C-h a electric-layout-rules posted:

Documentation:
List of rules saying where to automatically insert newlines.
Each rule has the form (CHAR . WHERE) where CHAR is the char
that was just inserted and WHERE specifies where to insert newlines
and can be: nil, `before', `after', `around', or a function of no
arguments that returns one of those symbols.

I tried:
code:
(setq electric-layout-rules '((";" . "after") ("{" . "around")))
But that gives me a syntax error when I eval the buffer. I'm not sure if setq is the wrong thing to be using or if I'm making the list wrong or what. I'm basically a huge noob and this is new to emacs 24 so I guess nobody is using it yet (meaning no example code on Google) despite it coming out a year ago.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
I'm not sure why you're getting a syntax error, but you need characters and symbols rather than strings.
code:
(setq electric-layout-rules '((?; . after) (?{ . around)))

aerique
Jul 16, 2008
This is cute, changing values with the mouse: http://nullprogram.com/blog/2013/06/07/

Although I've found (with playing with Unity lately and preferring haXe) that I'm much more of a 'code' person and less visually inclined than I thought.

Catalyst-proof
May 11, 2011

better waste some time with you
Has anyone taken a look at web-mode.el? I'm a lazy gently caress and I want to know if it works with js2-mode.

aerique
Jul 16, 2008
I've got a problem with for loops in eshell.

If I do:

code:
for GPLOT in gnuplot_scripts/*.gplot { echo "Processing $GPLOT..." }
It'll echo all the scripts in the directory like it should, but if I do:

code:
for GPLOT in gnuplot_scripts/*.gplot { echo "Processing $GPLOT..." ; gnuplot $GPLOT 1> /dev/null 2> /dev/null }
It'll go into an infinite loop processing just one specific file. It'll do the same if I leave out the echo command.

Googling hasn't helped much, anyone got an idea?

h_double
Jul 27, 2001
I don't have gnuplot installed, but I can do the following just fine:

code:
for FILE in foo/* { echo "processing $FILE "; cat $FILE 1> /dev/null 2> /dev/null }
What happens if you leave out the 1> and 2> redirects? Does gnuplot STDOUT/STDERR report anything interesting?


Running GNU Emacs 24.2 on MacOS 10.6.8 here.

aerique
Jul 16, 2008

h_double posted:

What happens if you leave out the 1> and 2> redirects? Does gnuplot STDOUT/STDERR report anything interesting?

No, it just reports some default progress on the script.

(BTW. Your cat example worked fine for me as well.)

Oh well, nevermind. The case I needed it for at work is in the past now so it isn't really relevant anymore. I switched to using multi-term.

aerique
Jul 16, 2008

aerique posted:

The one thing I would like is for the Helm buffer to open in the biggest available other-window, but I haven't been able to write a correct elisp function for that.

I managed to get this working. If anyone's interested I can put the code up on pastebin.

I've been meaning to put my config on GitHub but for sharing purposes I don't really like the state my config is in.

Catalyst-proof
May 11, 2011

better waste some time with you

aerique posted:

I managed to get this working. If anyone's interested I can put the code up on pastebin.

I've been meaning to put my config on GitHub but for sharing purposes I don't really like the state my config is in.

Definitely throw it up on Gist or something. It's always good to have it out in the open, in case anyone needs it later.

I hate the state my config is in. I keep meaning to declare Emacs config bankruptcy, but I just haven't gotten around to it :( That's like a major weekend project.

pgroce
Oct 24, 2002
I spent a ton of time a few months ago building a config with sensitive info (i.e., IP addresses, user names) in one file and the generic stuff in another, just so I could put it up on github or bitbucket or whatever. Still haven't done it. :effort:

I even set things up in org-mode. :sigh:

aerique
Jul 16, 2008

pgroce posted:

I spent a ton of time a few months ago building a config with sensitive info (i.e., IP addresses, user names) in one file and the generic stuff in another, just so I could put it up on github or bitbucket or whatever. Still haven't done it. :effort:

I even set things up in org-mode. :sigh:

I've been tempted to redo my config in org-babel like Sacha Chua did: https://dl.dropboxusercontent.com/u/3968124/sacha-emacs.html (from: http://sachachua.com/blog/2012/06/literate-programming-emacs-configuration-file/)

However, just separating the sensitive stuff from the other config options is something I should have done long ago and would give me immediate benefits.

Catalyst-proof
May 11, 2011

better waste some time with you
In terms of emacs.d customization, this is one of the best things I've ever done.

Lisp code:
(setq custom-file (concat dotfiles-dir "custom/" system-name ".el"))
(setq per-machine-config-file (concat dotfiles-dir "config/per-machine/" system-name ".el"))

(load custom-file 'noerror)
(if (file-exists-p per-machine-config-file)
    (load per-machine-config-file))
What this does is assume, in your ~/.emacs.d, a set of directories exist with Emacs Lisp files named after the actual machines you run Emacs on. So if you have machines Foo and Bar, your custom files will be ~/.emacs.d/custom/foo.el and ~/.emacs.d/custom/bar.el, respectively, and then you can run extra elisp code in ~/.emacs.d/config/per-machine/foo.el and ~/.emacs.d/config/per-machine/bar.el. This makes it super easy to keep work-related configurations out of your public repos, since you just gitignore those files.

This unfortunately does not have some kind of mechanism for customizations you want shared between computers.

You can also do this for the different operating systems you run Emacs on (i.e. OS X versus Linux), although I do that on the function level:

Lisp code:
(defun system-specific-gnu/linux ()
  (set-face-attribute 'default nil :height 120)
  (set-face-attribute 'default nil :font "Source Code Pro-12")
  (defadvice raise-frame (around wmctrl activate)
    (if (eq (window-system (ad-get-arg 0)) 'x)
        (x-send-client-message nil 0 (ad-get-arg 0)
                               "_NET_ACTIVE_WINDOW" 32 '(1))
      ad-do-it)))

(defun system-specific-darwin ()
  (set-face-attribute 'default nil :height 140)
  (set-face-attribute 'default nil :font "Menlo-14")
  (global-set-key [(control meta f2)] 'ns-toggle-fullscreen)
  (require 'smooth-scroll)
  (smooth-scroll-mode)
  (setenv "WORKON_HOME" (expand-file-name "~/.virtualenvs"))
  (add-to-list 'exec-path "/usr/local/bin")
  (setq browse-url-browser-function 'browse-url-generic browse-url-generic-program "open")
  (global-set-key (kbd "C-c C-e") 'browse-url)
  ;; A quick & ugly PATH solution to Emacs on Mac OSX
  (setenv "PATH" (concat (expand-file-name "~/System/bin") ":" "/usr/local/bin" ":" (getenv "PATH"))))

(let ((func-name (intern (concat "system-specific-" (symbol-name system-type)))))
  (if (fboundp func-name)
      (funcall func-name)))

EDIT: Oh hey I typed all this up and turns out we've already discussed per-machine configs in this thread.

Catalyst-proof fucked around with this message at 12:44 on Jul 18, 2013

aerique
Jul 16, 2008

Not only that, my Sacha Chua emacs-org-config suggestion apparently came from this thread as well :downsgun:

Those per-machine configs are nice though. I feel some config work coming up in the near future.

Notorious b.s.d.
Jan 25, 2003

by Reene
Emacs defaults to not distinguishing between C-i and <tab> for the sake of 1980s terminal users. I found this out today fighting with completion keybindings. Everyone who reads this thread should fix this right now because ugh

Lisp code:
;; 1. Distinguish C-i from <tab>
;; 2. Use C-i for completion since M-tab doesn't work.
;; 3. Rebind <tab> to what it was before.
(setq local-function-key-map (delq '(kp-tab . [9]) local-function-key-map))
(global-set-key (kbd "C-i") 'completion-at-point)
(global-set-key (kbd "<tab>") 'indent-for-tab-command)
Also autodetecting whether i'm on a vile tiny laptop/netbook display.
My normal display font doesn't cut it on a 1280x800 display 10" from my face.
Lisp code:
;; On small monitors, use 8x13.
;; On large, use 9x15.
(defun set-my-default-font (my-fontname)
  (set-default-font my-fontname)
  (setq default-frame-alist
	(append `((font . ,my-fontname)) default-frame-alist)))

(if (< (x-display-pixel-width) 1600 )
    (set-my-default-font "8x13")
  (set-my-default-font "9x15"))

Zombywuf
Mar 29, 2008

Why are you using fixed pixel sized fonts in the year of our lord two thousand and thirteen?

Adbot
ADBOT LOVES YOU

Deacon of Delicious
Aug 20, 2007

I bet the twist ending is Dracula's dick-babies
If anyone is familiar enough with the autocomplete from http://cx4a.org/software/auto-complete/ I have a couple of questions I couldn't answer from the manual:

1) elisp has quick help popups that describe the selected autocomplete candidate. Is there a way to do this for other languages?

2) Many of the completions have a single letter on the right side, such as 'a', 'd', 'f', or 's'. What do these letters mean?

  • Locked thread