Remote SUDO Access With Tramp

I was reading some of the old posts from the excellent emacs-fu when I came across this post describing how to access root-owned files as a regular user. It was a nice post and cleared up an arcane piece of syntax that I never understood. In order to edit a root-owned file on the local host you enter something like:【Ctrl+x Ctrl+f/sudo::<path-to-root-owned-file>. The double colon seemed different from other similar constructs but all that’s happening is that /sudo:: is really just a shortcut for sudo‘s default, which is /sudo:root@localhost:.

That’s interesting and cleared up something that never made sense to me but the interesting lesson from the post occurred in the comments. One of the commenters complained that this still didn’t help with the common case of wanting to edit root files on a remote machine. If you try to do this, Emacs (Tramp, really) complains that sudo can only be used on the local host. However, it turns out that you can use the Tramp multihop facility to enable this functionality. This is explained in detail in the info page at Tramp > Configuration > Multi-hops, but the TL;DR is to add the three commands

(require 'tramp)
(add-to-list 'tramp-default-proxies-alist
             '(nil "\\`root\\'" "/ssh:%h:"))
(add-to-list 'tramp-default-proxies-alist
             '((regexp-quote (system-name)) nil nil))

to your .emacs or init.el file. Then you can edit remote root files with 【Ctrl+x ctrl+f/sudo:root@remote-host:<path-to-root-owned-file>.

Posted in General | Tagged | 3 Comments

Hiring Writers

Hitesh Sarda has an amusing post on How I Hire Writers. Much has been written recently about the dysfunctional madness that is the tech hiring process. Sarda imagines the same process applied to writers applying, say, to a newspaper or magazine. Once you know the premise you can almost write the post yourself:

  • Offload the initial screening to HR by giving them relevant keywords such typing speed.
  • Have an initial screening phone interview in which they ask questions such as
    • Spelling of conscientious
    • Explanation of the Oxford comma
    • Asking the candidate to recite tongue twisters
  • Those candidates who pass the screening interview are invited to an on-site interview in which the interviewers dig deeply into
    • Knowledge of the Elements of Style
    • Spelling and grammar
    • Obscure facts about the areas in which they will be writing
    • Questions about word roots

When you see these tactics in an unfamiliar context their absurdity becomes obvious. Sadly, hiring managers are not apt to read Sarda’s post and if they do you can already imagine their explanations as to why they have to do things this way. No wonder so many people are starting their own businesses—anything would be better than going through this silliness.

Head on over and enjoy Sarda’s post. It will make your day.

Posted in General | Leave a comment

Emacs 24 ELPA Update

In my ELPA With Emacs 24 post, I documented some of the problems I was having getting ELPA to work with Emacs 24 and showed some Elisp to work around the problem. Fortunately, my readers are a lot smarter than I am and suggested better ways of getting things to work.

The answer turns out to be pretty simple. I replaced all my special code for setting paths and requiring package with:

(package-initialize)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/"))

and left everything else the same. So far that seems to be working perfectly. The documentation isn’t really clear on this and, in fact, hints that putting

(package-initialize)

in your .emacs or init.el file can cause problems with other packages. I haven’t seen that and neither have any of my commenters so unless I run into problems later, my recommendation is to simply add the package-initialize near the top of your .emacs or init.el.

None of this means, of course, that you won’t have to configure some of the packages you load with ELPA but at least Emacs won’t throw an error during startup because of missing packages. Thanks to Seth, Philipp, and Foo for their helpful comments.

Posted in General | Tagged | 1 Comment

You Can’t Make This Stuff Up

Just when you think you’ve heard it all, we get a story like this. Scum spammers, masquerading as SEO consultants, have recently been flooding blogs with comment spam for an insurance agency in Australia. We here at Irreal get spam for similar (but not, apparently, the same) outfits on a regular basis.

Now Google has changed the rules a bit and fixed things so that “legacy spam” is actually damaging to the concerns that it was supposed to help. In response, the company has sent out emails asking (demanding?) that the blogs victimized on their behalf now remove these links (because they “may be harmful either to the future marketing and reputation of [our company] or our search results”) and to notify them when said links have been removed. I really wish that I had received one those emails but, sadly, I remove spam from the comments as they come in so I won’t have the opportunity to make a choice reply.

Josh Marshall of Talking Points Memo received one of these emails (see the story like this link) and summarized the situation as the company paying SEO consultants to spam blogs around the globe and then sending cease and desist notices when the scheme backfires. I’m not sure the email rises to the level of a cease and desist notice but it is rather demanding, especially in its insistence that the sender be notified when the links are removed.

If you were under the delusion that shameful behavior has boundaries, this story should disabuse you of the notion.

Posted in General | Tagged | Leave a comment

Line Numbering

DJCB, over at Emacs-Fu, takes note of the new line number command in Emacs 24 that Sivaram wrote about in Got Emacs? and offers up a few suggestions of his own. He shows a very nice trick for accomplishing the same thing and more using replace-regexp. It’s a little more complicated than rectange-number-lines so you probably won’t want to use it except for those cases where rectangle-number-lines (along with its optional FORMAT argument) can’t give you the desired result. Of course, if you’re still using an older version of Emacs it’s a nice way of getting the same functionality that rectangle-number-lines provides.

Posted in General | Tagged | Leave a comment

Magnar Sveen Rocks Emacs

Many (many) years ago when I was a freshman at RPI, we called the weekly Physics mass lecture “The Magic Show” because the lectures were spectacular demonstrations that illustrated whatever principle we were studying that week. This week I had the same feeling as I watched Magnar Sveen (of Emacs Rocks! fame) deliver a talk at Web Rebels in Oslo. The sound quality was a little substandard and the pace was rapid but like those old physics lectures it was a spectacular demonstration. In this case, a demonstration of the power of Emacs and its extensibility.

Sveen started by saying that unfortunately Emacs doesn’t have a slide show capability and then put one together right before our eyes. Then he spent the rest of the 18 minutes showing off some of the micro-optimizations he’s developed to speed up his editing. One of these, his multicursor enhancement, was startling and has to be seen to be believed.

This is a really great video, sort of like Emacs Rocks! on steroids. You won’t learn how to program these enhancements or even how to use them, just what’s possible with Emacs. Fortunately, all of Sveen’s code is available on GitHub so you can download the code and try it yourself. The multiple cursor stuff is still very young but worth playing with. I’m looking forward to seeing it on Marmalade when it gets a little more mature.

If you’re an Emacs user and especially if you enjoy the Emacs Rocks! videos you should definitely spend 18 minutes on this talk. You won’t be sorry.

Posted in General | Tagged | Leave a comment

Common Lisp For Noobs

Lori Holden over at Ghost Opera, Ltd has a nice post with advice for noobs wanting to get started with Common Lisp. As Holden points out, Common Lisp is beautiful and powerful but has some sharp edges and no commonly agreed upon starting point for newcomers.

The post is aimed at getting the neophyte up and running by listing some references and tools and then walking through a (toy) project. For tools she recommends

  • Emacs/Slime
  • SBCL
  • Quicklisp
  • CL-Project
  • Buildapp and
  • ASDF

That seems like a reasonable list, and truth to tell, I use almost that exact set of tools for all my Lisp work. The only difference is that I use Zach Beane’s quickproject instead of cl-project. Part of that is because I discovered quickproject first but it’s also because cl-project uses a method of package management that differs from what I (and, I think, most Lisp programmers) am used to.

The method pushed by cl-project is based on the style recommendations of Ariel Networks, which I find less than compelling. Still, others can and do disagree so it’s worth checking them and cl-project out if you’re inclined. Holden has a direct link to the Ariel style guide so she’s apparently an adherent.

There’s nothing in this post that will be new to anyone who’s the least bit familiar with Common Lisp but if you’re a newcomer and wondering how to get started, this is a valuable post with lots of good information.

Posted in Programming | Tagged | Leave a comment

ELPA With Emacs 24

I just installed Emacs 24 and, as expected, everything went very well except for the package system, ELPA. I don’t have very many packages that I load with ELPA so at least the number of problems were limited.

First, following Xah Lee’s Guide on Emacs 24 Package System page, I moved the old ~/.emacs.d/elpa directory out of the way and then reloaded my packages. The first problem is that you need to replace the

(when
    (load
     (expand-file-name "~/.emacs.d/elpa/package.el"))
  (package-initialize))

with

(require 'package)

After that change I was able to add Marmalade to the list of package sites.

The next problem was that when I restarted Emacs, I got an error saying it couldn’t load smex, one of the packages that I load with ELPA. Everything seemed OK: smex was loaded onto my machine and seemed fine. The bit of Elisp in init.el was what the documentation said it should be but I couldn’t get it to load from init.el. I went searching on the Web and after a few useless links I found this page on Emacs 24 Package System Problems, again from Xah Lee. In order to get things to work you have to add an explicit load path for some of the packages (smex, magit, dired+, and key-chord for me). My first pass at this was to add commands to explicitly add the load paths:

(add-to-list 'load-path "~/.emacs.d/elpa/smex-1.1.2/") ; XXX Emacs bug
(require 'smex)
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
...

This is annoying because the path will have to be changed when I upgrade. It’s doubly annoying because ELPA worked just fine without having to do this in Emacs 23. Rather than keep dealing with this every time I upgrade one of the problem packages, I added

(defconst elpa-loads '("smex" "magit" "dired" "key-chord"))
(mapc (lambda (p) (if (file-directory-p p) (add-to-list 'load-path p)))
      (directory-files "~/.emacs.d/elpa" t
                       (concat "^\\("
                               (mapconcat 'identity elpa-loads "\\|")
                               "\\).*")))

to my init.el. With that change, the only maintenance required is to add any new problem packages to elpa-loads.

The Emacs 24 ELPA problem appears, from some of the other links I looked at, to be that Emacs 24 deals with the ELPA packages after it has finished processing the .emacs or init.el file and, therefore the .emacs or init.el file knows nothing about the packages. That means you can’t set package variables because they haven’t been loaded yet. As far as I could find out, the only solution is to load the files with require and that requires that there be a path to the .el or .elc files.

Doubtless, this will all be resolved soon so I’m not overly exercised about it. Now that I have things working again, it’s time to explore the new Emacs 24 and see how it improves my life.

Update: Added explicit check for directory when setting paths.

Posted in General | Tagged | 10 Comments

Emacs Rocks! #11

The always entertaining and informative Magnar Sveen has a new episode of Emacs Rocks! up. In Episode 11 he demonstrates swank.js a package that brings the JavaScript REPL to Emacs in much the same way that swank brings us the Common Lisp REPL.

If you are a JavaScript programmer and aren’t already using swank-js you should view Sveen’s video without delay. He shows a simple animation of a bouncing ball and then makes changes to the code that are immediately reflected in the animation. This is good stuff.

Posted in Programming | Tagged | Leave a comment

The Emacs 24 Package System

Back in March, I blogged about installing ELPA in Emacs 23. At the time I pointed to a page by Xah Lee on how to do this. Now that Emacs 24 is out it’s worthwhile revisiting the Emacs package system. In Emacs 24, ELPA is built in so all that’s necessary is to set the repositories that you want to get packages from.

Again, Xah Lee has us covered with an updated page. If you’ve recently updated to Emacs 24 and don’t know about ELPA, you should take a look at Lee’s page about it. He’s got all the information on how to use it and how to upgrade from ELPA for Emacs 23 to ELPA for Emacs 24. Once you get ELPA set up, everything is much easier. You can download packages and have them available without having to worry about setting up paths or special directories. It’s easy to update and delete packages so there’s no need to worry about checking in with a package’s home page to see if there’s an update—ELPA will tell you.

If you’re an Emacs user and aren’t using ELPA you’re making your life more difficult than it has to be. Seriously, check out Lee’s page and get ELPA up and running. It will make your life a lot better.

Posted in General | Tagged | 2 Comments