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
Catalyst-proof
May 11, 2011

better waste some time with you

Zombywuf posted:

Anyone know how to get the current revision and other version control info from a file to create a org-capture template. The idea is to be able to insert a note about the file I currently have open, so something like this:
code:
(defun generate-file-template ()
  (let ((file-name (buffer-file-name))
	(line-number (line-number-at-pos)))
    (concat "* " file-name ":" (int-to-string line-number) " %T")))
will insert a note like:

What I want is to be able to check if the file is under version control and get info about the repository and revision but the functions under dvc don't seem to have much in the way of introspection. Anyone know how to get information out of it?

Hey Zombywuf, org-git-link.el looks like it might do what you need: http://orgmode.org/worg/org-contrib/org-git-link.html (Found a raw copy here: https://github.com/ReimarFinken/org-git-link)

Adbot
ADBOT LOVES YOU

Zombywuf
Mar 29, 2008

Awesome, that looks even better than what I was trying to do :-)

Catalyst-proof
May 11, 2011

better waste some time with you
Does anyone have an opinion on JDEE, Malabar, or a comparison between the two? I feel I may be sucked into Java development soon.

DrMelon
Oct 9, 2010

You can find me in the produce aisle of the hospital.
I just started using Emacs today, and I'm currently going through the little tutorial.

I can't stop. Send help.

Zombywuf
Mar 29, 2008

DrMelon posted:

I just started using Emacs today, and I'm currently going through the little tutorial.

I can't stop. Send help.

There is no help, you are ours now. Join us.

tip: try M-/ for auto completion

fishbacon
Nov 4, 2009
wonderful yet strange smell

DrMelon posted:

I just started using Emacs today, and I'm currently going through the little tutorial.

I can't stop. Send help.

No help needed, you're one of us now. One of us!

Tip: Menus are not for you any more (put this in your .emacs file):
code:
(tool-bar-mode -1)
(scroll-bar-mode -1)
(menu-bar-mode -1)
less scary tip:
i-search is great for navigating a file, C-s has become second nature to me whenever I need to find something in a file.

fishbacon fucked around with this message at 16:17 on Jan 8, 2012

Zombywuf
Mar 29, 2008

Also, how to get help:

C-h a - apropos, lets you search all the built in documentation
C-h b - opens a new buffer containing all the key bindings in the current buffer
C-h m - opens a new buffer with help for the current modes active (e.g. python-mode, help-mode, etc...)

The C-s search Mr. Fish mentions is extremely useful when it comes to the last 2 buffers. I usually explore new modes by searching through the help buffers that are opened. The function names that are displayed are hyperlinks you can follow with a mouse click or <enter>.

Also if you open the minibuffer for a command with M-x then you get tab completion of commands. The list of functions that appears when you hit tab twice is also searchable (you may be noticing a theme).

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Things that took me way too long to learn but are extremely helpful:

M-<Space> is the default keybinding for the "just-one-space" function. It replaces all the whitespace around you with "just one space". It's extremely useful when merging two lines like:

code:
foo (aLongThing,
     anotherLongThing);
into:

code:
foo (aLongThing, anotherLongThing);
simply go to the end of the line (C-e), delete (C-d) and use your magic (M-<Space>).

M-m goes to the first non-whitespace char of the line. It's like a better C-a.

BusError
Jan 4, 2005

stupid babies need the most attention

Suspicious Dish posted:

Things that took me way too long to learn but are extremely helpful:

M-<Space> is the default keybinding for the "just-one-space" function. It replaces all the whitespace around you with "just one space". It's extremely useful when merging two lines like:

code:
foo (aLongThing,
     anotherLongThing);
into:

code:
foo (aLongThing, anotherLongThing);
simply go to the end of the line (C-e), delete (C-d) and use your magic (M-<Space>).

M-m goes to the first non-whitespace char of the line. It's like a better C-a.

I use 'just-one-space ALL the time. I also use 'delete-blank-lines (C-x C-o) all the time which is like the same thing but for lines.

pgroce
Oct 24, 2002
It isn't very old-skool of me, but I'm really digging ELPA. It's not quite like having apt-get for Emacs, but it's close. And it ships with Emacs 24, so there's some incentive to upgrade. :)

If anyone decides to play around with it, you should probably include the Marmalade package repository in addition to the "official" repo, thusly:

code:
(require 'package)
(add-to-list 
 'package-archives 
 '("marmalade" . "http://marmalade-repo.org/packages/"))
(I needed the require, not sure if everyone will.)

Lots of nifty stuff in there. It's nice opening an Apache config, thinking "I bet someone's written a mode for this" and getting it installed in under a minute. :allears:

Zombywuf
Mar 29, 2008

More org mode fun. I've been playing with babel and I've just found out how to make it do SQL. A fairly common workflow for me is:

1) Oh it broke, maybe the clue is in the db.
2) Run a bunch of queries.
3) Curse my own stupidity.

Step 2 is often a pain as I often need to run a bunch of similar queries and keep a log of all the queries run and their output for reference. Org babel lets me do this by its "every language now has a workbook magic" and I'm guessing a lot of other people do so here's how. To do this for postgres you need a src block like this:
code:
#+begin_src sql :engine postgresql :cmdline mydbname
select * from stuff;
#+end_src
The :engine parameter tells ob-sql what sql engine to use, others available are mysql and msosql. The :cmdline parameter is just inserted into the command line of whatever program it is run under, for psql the first argument is the name of the db to connect to. With the point on this block I can just C-c C-C and the result of the query is inserted into the buffer as a table.

You can insert a src block by typing <s<tab> btw.

You can also use parameters, I'm using org mode 7.7, in 7.8 replace srcname with name. Parameters are delimited with a $ and are specified with :var param=value. Sadly it's just done with raw string insertion so features like using named tables as parameters are not going to work, to use a string as a parameter you need to double escape it like so:
code:
#+srcname: updatedsince
#+begin_src sql :engine postgresql :cmdline mydbname :var date="'2012-01-01'"
select * from stuff where updated >= $date;
#+end_src
If you run it with C-c C-c the default value will be inserted, to use other values insert a line into the buffer like so:
code:
#+call: updatedsince(date="'2012-01-10'")
and C-c C-c it. The result block inserted will have the params included so you can change the params and re-run and a new results block will be inserted.

Then comes babel's party trick, you can pass the output of one codeblock to the input of another, even across languages. For example:
code:

#+begin_src sql :engine postgresql
create table numbers (
  x int not null
);
#+end_src

#+results:
| CREATE TABLE |

#+begin_src sql :engine postgresql
insert into numbers (x) values (1);
insert into numbers (x) values (2);
insert into numbers (x) values (3);
#+end_src

#+results:
| INSERT 0 1 |
| INSERT 0 1 |
| INSERT 0 1 |

#+srcname: getnumbers
#+begin_src sql :engine postgresql
select x from numbers;
#+end_src

#+srcname: addone
#+begin_src emacs-lisp :var input=()
(mapcar
 (lambda (x)
   (+ (string-to-number (car x)) 1))
 (cdr input)) -- skip the header row
#+end_src

#+call: addone(input=getnumbers())

#+results: addone(input=getnumbers())
| 2 | 3 | 4 |
Org babel is a bit rough around the edges so it takes a bit of hassle to get it to work, hope this saves someone some time.

BusError
Jan 4, 2005

stupid babies need the most attention
Maybe someone here can help me out with a problem I'm having. I'm using multi-web-mode right now, and for some files that mix JavaScript and HTML, it freaks out when I try to indent. It belches several lines of just the character 'a' onto the screen and then says

code:
Lisp nesting exceeds `max-lisp-eval-depth'
in the minibuffer. It works fine on some files, and so far I haven't figured out the pattern that causes it to break. Any ideas?

mustermark
Apr 26, 2009

"Mind" is a tool invented by the universe to see itself; but it can never see all of itself, for much the same reason that you can't see your own back (without mirrors).
Have they invented a solid web/multi-filetype mode yet? MUMAMO is horrible and crashes on me all the loving time, and basically drove me to Textmate/Sublime 2.

Catalyst-proof
May 11, 2011

better waste some time with you
I honestly can't stand using any of the multi-modes that are available. All of them suck in one way or another. For the most part I try to keep things partitioned out into separate files. This is definitely one place where Emacs could use a ton of improvement.

Beef
Jul 26, 2004
Random protip:

Many Emacs key bindings also work in linux terminals and any OSX editing fields. For example C-a or C-a.

Zombywuf
Mar 29, 2008

ITYM C-e, but yeah, it's really cool when I suddenly realise I'm using those bindings outside of emacs and have been for ages. There's even a dabbrev-expand in readline which is not bound by default, enable it with:
code:
bind '"\e/":dabbrev-expand'
in your .bashrc.

Note: in SQL Server Management Studio C-e is "execute current buffer". Be very careful.

pgroce
Oct 24, 2002

Zombywuf posted:

Note: in SQL Server Management Studio C-e is "execute current buffer". Be very careful.

On a similar note, if you bind meta to command on a Mac, you've probably unexpectedly quit your web browser before by trying to refill a paragraph.

If you want to get freaky about using Emacs outside Emacs, there's an Edit With Emacs Chrome extension, and Firemacs for Firefox. I frankly don't see much use for these, but if you do lots of complex editing in HTML textareas and, um, don't want to just copy and paste for some reason, maybe it would be useful.

Or you could just run emacs-w3m! :suicide:

Catalyst-proof
May 11, 2011

better waste some time with you

pgroce posted:

Or you could just run emacs-w3m! :suicide:

I do this, it rules

Also OS X surprisingly supports a ton of Emacs keybindings. I think there was a post earlier in the thread about it.

Zombywuf
Mar 29, 2008

You seem to have changed your tune on w3m Fren, how much effort is it to get it working?

Aside, sometimes certain things (flymake mostly) generate 2 line messages, which makes the window at the bottom move up one line. This can be really jarring, anyone know how to make the bottom window shrink instead of the top window shrinking and the bottom moving?

Catalyst-proof
May 11, 2011

better waste some time with you
Hahah that's right, at some point in the thread I mentioned it may have been rather spergy, but w3m has replaced a lot of my web browsing. It's mostly just getting used to its capabilities and key navigation. It wasn't a lot of effort to get working. Just had to brew install w3m, check out emacs-w3m somewhere (cvs -d :pserver:anonymous@cvs.namazu.org:/storage/cvsroot co emacs-w3m), and load it up.

I have avatars and sigs disabled, and here's the keybindings I use for navigating SA threads:

code:
(defun w3m-somethingawful-navigate-next ()
  (interactive)
  (goto-char (point-min))
  (search-forward "Next ›")
  (w3m-view-this-url))

(defun w3m-somethingawful-navigate-previous ()
  (interactive)
  (goto-char (point-min))
  (search-forward "‹ Prev")
  (w3m-view-this-url))

(add-hook 'w3m-mode-hook (lambda ()
                           (define-key w3m-mode-map ":" 'w3m-somethingawful-navigate-next)
                           (define-key w3m-mode-map ";" 'w3m-somethingawful-navigate-previous))
Other useful things to know:

  • a adds a bookmark. They're split up into sections so you'll get asked which section you want to put it in.
  • v to view bookmarks, V to view in a new tab.
  • R to reload the page, r to redraw the page to accommodate a different frame width.
  • g to go to a new URL, G to go to a URL in a new tab.
  • C-c C-w to close a tab,
  • C-c C-p and C-c C-n to navigate between tabs.
  • TAB and S-TAB to navigate between links on a page.
  • left and right to navigate the history.

Zombywuf
Mar 29, 2008

I have fallen at the first hurdle, the ubuntu packages wont byte compile :-(

Catalyst-proof
May 11, 2011

better waste some time with you
Errm, I may have elided some steps. Check http://emacs-w3m.namazu.org/#installation

Neslepaks
Sep 3, 2003

Fren posted:

This is a really stupid request. Does anyone know of a more thorough font-lock mode for Common Lisp? I feel like more stuff, like numbers, symbols, functions known to be provided by the implementation, etc. should be highlighted.

I'd like to know this too.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Is there a way to swap the command and control keys in OSX for emacs only?

Also, I don't really understand why anybody would caps lock as control. I use caps lock a lot (people don't?) Most of the control combinations are on the left hand. I'd like to make stuff like C-x C-s easier.

RICHUNCLEPENNYBAGS
Dec 21, 2010

baby puzzle posted:

Is there a way to swap the command and control keys in OSX for emacs only?

Also, I don't really understand why anybody would caps lock as control. I use caps lock a lot (people don't?) Most of the control combinations are on the left hand. I'd like to make stuff like C-x C-s easier.

Maybe check out Aquamacs. It doesn't actually solve this problem but it recognizes a lot of common OS X shortcuts like apple-S to save.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
The purpose is to use emacs in the same way that I do on Windows 7 at work, so that won't really help me.

pgroce
Oct 24, 2002

baby puzzle posted:

Is there a way to swap the command and control keys in OSX for emacs only?

Also, I don't really understand why anybody would caps lock as control. I use caps lock a lot (people don't?) Most of the control combinations are on the left hand. I'd like to make stuff like C-x C-s easier.

Check out the following variables to put the modifier keys where you want them:

code:
ns-alternate-modifier 
ns-command-modifier
ns-control-modifier
ns-function-modifier
ns-option-modifier
ns-right-alternate-modifier
ns-right-command-modifier
ns-right-control-modifier
ns-right-option-modifier
They take symbols like 'super and 'meta, to map the correct Emacs modifier concept onto the physical key you want.

I used to use caps lock a fair amount, but I switched caps lock and control anyway and I think it's an improvement, especially since I can get 80% of caps lock by typing in lower-case and running upcase-word (or just M-u at the command line, as long as I've set -o emacs). Since that's most of where I use all-caps, it meets my needs nicely.

I could streamline that more by writing a function that essentially works like upcase-word does by default, only backwards, so I wouldn't have to enter a negative prefix arg or go back a bunch of words before running it. Wouldn't help me with terminal prompts, alas.

(Muddles about with elisp for a few minutes...)

...and here's a function to do just that. :)

code:
(defun pg/upcase-word-reversed (&optional arg)
    "Convert preceding word (or ARG words) to upper case (in the
style of `upcase-word'), moving to start of previous word. Unlike
`upcase-word', this function ignores negative arguments."
  (interactive "p")
  (let ((nwords (or (and (or (eq arg nil) (< arg 0)) 1)
                     arg)))
    (backward-word nwords)
    (save-excursion
      (upcase-word nwords))))

(global-set-key [(shift meta u)] 'pg/upcase-word-reversed)
e: fix table-breaking comment and superfluous use of let*

pgroce fucked around with this message at 19:25 on Feb 5, 2012

Catalyst-proof
May 11, 2011

better waste some time with you
So, this kind of rules. Emacs-chess mode, which not only allows you to play across Emacs instances and with the standard Chess engines, but also online at FICS servers like freechess.org. Comes with ASCII and graphical display.

Only registered members can see post attachments!

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
How do I pare down the search path of a find-grep-dired (or whatever other function that might do the same thing) so that it will not take literally hours?

I have two specific folders I want to look in that have a common base, but I want to avoid searching everything else under that base. I also only need to search headers.

For example, I want to search both of these patterns:

d:/dev/project/highlevel/code/*.h
d:/dev/project/lowlevel/code/*.h

Catalyst-proof
May 11, 2011

better waste some time with you

baby puzzle posted:

How do I pare down the search path of a find-grep-dired (or whatever other function that might do the same thing) so that it will not take literally hours?

I have two specific folders I want to look in that have a common base, but I want to avoid searching everything else under that base. I also only need to search headers.

For example, I want to search both of these patterns:

d:/dev/project/highlevel/code/*.h
d:/dev/project/lowlevel/code/*.h

I'd just use M-x rgrep for this. Asks you what you want to search for, then a filename regex, then a search location. Don't know if there's a way to do a search and replace from rgrep though, so if that's why you're using find-grep-dired, I'm afraid I don't know :-/

Is anyone using Gnus and w3m to read HTML e-mail? I'm having an issue where entire messages that are formatted rather sanely are being rendered entirely in the face w3m-bold, which is really pretty distracting.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I guess there is something wrong with my stuff because grep exits abnormally before finding everything. Oh well!

-----

I'm feeling pretty let down by these tools so far. As hard as I try, I have yet to accomplish any work. Where are the supposed productivity gains?

Catalyst-proof
May 11, 2011

better waste some time with you

baby puzzle posted:

I guess there is something wrong with my stuff because grep exits abnormally before finding everything. Oh well!

-----

I'm feeling pretty let down by these tools so far. As hard as I try, I have yet to accomplish any work. Where are the supposed productivity gains?

See if there's an error at the bottom of the *grep* buffer. When you run rgrep, the resultant buffer shows you the entirety of the command that it's running, essentially in a command line, to perform the grep. Take that command and run it at a terminal prompt and see if it errors out irrespective of Emacs.

Learning Emacs is work. Depending on what you're doing, and how long you've been doing it in another editor, and what you're trying to do in Emacs, it may be some time before you can do all of what you want, comfortably, in an intuitive way, and routinely. Emacs provides tons of tools to help diagnose what you may be doing wrong, and documentation to figure out how Emacs does what you're trying to do. Don't give up.

If you could be a bit more specific about what it is you're trying to do, maybe we can help.

equation groupie
Feb 7, 2004

debased and dread pilled

Fren posted:

...w3m has replaced a lot of my web browsing...

Oh god, why aren't you using conkeror instead of this?

Catalyst-proof
May 11, 2011

better waste some time with you

vlack posted:

Oh god, why aren't you using conkeror instead of this?

Because Firefox.

orphean
Apr 27, 2007

beep boop bitches
my monads are fully functional
I do all my web browsing using wget and a cron job. :shepface:

Catalyst-proof
May 11, 2011

better waste some time with you

orphean posted:

I do all my web browsing using wget and a cron job. :shepface:

I'd honestly just prefer if there were a sort of Gopher-style web with image and LaTeX support and precious little else. As it stands, w3m allows me to browse modern websites in a terminal, and it's super easy to move stuff from Emacs into it. Like, check it out: (M-x boxquote-describe-function RET find-grep-dired RET)

code:

,----
| find-grep-dired is an interactive compiled Lisp function in
| `find-dired.el'.
| 
| (find-grep-dired DIR REGEXP)
| 
| Find files in DIR containing a regexp REGEXP and start Dired on output.
| The command run (after changing into DIR) is
| 
|   find . \( -type f -exec `grep-program' `find-grep-options' \
|     -e REGEXP {} \; \) -ls
| 
| where the car of the variable `find-ls-option' specifies what to
| use in place of "-ls" as the final argument.
| 
| [back]
`----

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.

Fren posted:

If you could be a bit more specific about what it is you're trying to do, maybe we can help.

I am just trying to do a simple search and replace across an entire project, which will probably touch about 100 files. This takes seconds in Visual Studio, because it has everything indexed. Emacs has no concept of where my source code is (another issue I'd like to fix), and so it winds up searching through a bunch of unrelated stuff, taking hours to do.

If the issue was urgent then I'd just do it with Visual Studio.

Maybe first I need to figure out how to get an EDE project set up. I assume that once I have one, then emacs will index everything in it and I can search/replace throughout the project easily.

Catalyst-proof
May 11, 2011

better waste some time with you
If you're having trouble with search and replace, I'm not sure I would recommend trying to get EDE working.

You said grep exits abnormally when you use find-grep-dired. What error are you getting? The function documentation I posted above describes the exact command line that is run to perform the grep. Run it outside of Emacs, and see if it comes up with an error. If it doesn't, run it within Emacs after flipping debug-on-error on (M-: (setq debug-on-error t) RET), and post the Backtrace that you get.

find-grep-dired drops results to a dired buffer, with which you can % m *.h to mark your header files, and then Q oldstring RET newstring to perform the replace, then C-x s to save all the files you changed during the replace. Why doesn't that work for you?

Also, find-name-dired takes a filename regex and provides you with a dired buffer, with which you can repeat the query replace described above. Why doesn't that work for you?

There are about 2 or 3 dozen ways to accomplish variants of what you're trying to do: http://www.emacswiki.org/emacs/CategorySearchAndReplace Typically, the onus is on you to determine which solution fits your needs; this thread is here to help, but you're still not providing any detail about your problem. How many files are in your project? What's taking 'hours' to perform, the actual finding of files in the directory (which should be a single fstat call per file), the searching within files to find the needle you want to replace (which, given a hundred files, should not take very long at all), the actual replacement?

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Apparently I'm searching through 300,000 files, which is why it doesn't get anywhere.

I'm trying to reproduce what was happening before, but it appears to be working now. Oh well. I can certainly just manually run this search multiple times in various locations, but that really isn't reasonable for actually getting work done.

Adbot
ADBOT LOVES YOU

Catalyst-proof
May 11, 2011

better waste some time with you

baby puzzle posted:

Apparently I'm searching through 300,000 files, which is why it doesn't get anywhere.

I'm trying to reproduce what was happening before, but it appears to be working now. Oh well. I can certainly just manually run this search multiple times in various locations, but that really isn't reasonable for actually getting work done.

Why would you have to run it multiple times in various locations? Why would you have to do so manually, when Emacs has a macro system, and, in the worst case, allows you to write what you want to do in Lisp and automate it?

I think you may be going about this the wrong way. Don't think about how to do something in Emacs, think about what you want to do. Come up with some essential vocabulary for it. In this case, search and replace on files. Check the manual (C-h r i search TAB). The first result I find is 'search and replace in multiple files', which brings you to section 28.3.6, which describes using a TAGS file (caching file information much like Visual Studio does) and using tags-query-replace to perform the search and replace, which will only operate on the files that were cached in the TAGS file. The next obvious question is, how do you create a TAGS file? C-h r i tags finds me the term 'tags and tag tables', which brings you to section 28.3, not far from where you started, but with a menu of contents which includes 'Create Tags Table'. And so on.

Yes, you're probably going to be doing this sort of thing a lot as you get the hang of Emacs. But all of this knowledge starts congealing together, and soon you'll start to have a more comprehensive idea of what Emacs is capable of. Emacs is so insanely powerful and it's a joy to use when all these things start coalescing in your head.

EDIT: Emacs doesn't make your life easier. It makes your life harder, which gives you the tools so that /you/ can make your life easier.

Catalyst-proof fucked around with this message at 20:22 on Feb 28, 2012

  • Locked thread