Categories
Digital rights Law & Freedom Emacs GNU/Linux Free Software & Open Source News Programming & Web Development

Make Emacs yasnippet work with html-helper-mode

code
Yasnippet is a great emacs minor mode that lets you have lots of code snippets easily at hand. Also you can create your own snippets in a very easy way without needing to write them in emacs lisp. Basically, like textmate shortcuts for emacs.

I use html-helper-mode to edit all my html code, but yasnippet works with html-mode only out-of-the-box. To make it work with html-helper-mode, add ‘html-helper-mode-hook’ to yasnippet.el on line 121:

It should look like this:

'(ruby-mode-hook actionscript-mode-hook ox-mode-hook python-mode-hook html-helper-mode-hook))

Then make a symlink to html-mode on the snippets folder. Assuming you are on yasnippets snippets/text-mode/ directory, type:


ln -s html-mode/ html-helper-mode

And now all html snippets will be available on html-helper-mode too.

Image is Creative Commons byitspaulkelly
Categories
Emacs GNU/Linux Free Software & Open Source

Identica mode for Emacs update: support for any Laconica server

I’ve updated identica-mode for Emacs and now has a way to connect to any laconica server, instead of just identi.ca.

To configure add this to your .emacs file, or your customizations file or your choice:

(setq laconica-server "myserver.com")

I’m working on publishing the git repository of the project. In the meantime you can download it here.

Categories
Emacs GNU/Linux Free Software & Open Source

Identi.ca mode for Emacs

Status.net logo

Identi.ca is a free software microblogging service, similar to Twitter, based on the Status.net code base. I recently needed to update my status from Emacs, since its faster for me and easier. I’ve been using an an Emacs mode to update my Twitter account, but there was nothing to use for my Identi.ca account. And seeing there’s a Vim plugin, I thought someone, like me, needed an Emacs mode too.

So I forked the original twittering-mode to use it with the Identi.ca platform, using its Twitter compatible api.

System Requirements

  • GNU Emacs 22 or later
  • Linux, Mac OS X, BSD or any Unix based OS (requires wget)

Download

Download the latest stable release of Emacs Identica-mode

Or get the latest development code from the Git repository at
http://git.savannah.gnu.org/cgit/identica-mode.git

Installation

Copy the identica-mode.el file to your Emacs elisp files directory (.emacs.d/ in Ubuntu)
Then add the following to your .emacs (or your preferred customizations file)

;;; Identi.ca mode
(require 'identica-mode)
(setq identica-username "yourusername")

If you want to authenticate using simple authentication, create a file ~/.authinfo with the following contents:

machine servername login yourusername password yourpassword

Replace servername with your server (if connecting to Identica service, use identi.ca as server name), yourusername and yourpassword with your information.

You can also authenticate using OAuth, specially if you log in with an OpenID account which has no password. To use OAuth authentication (requires using oauth.el), add the following to your .emacs file:

(setq identica-auth-mode "oauth")

If you want to post from the minibufer without having identica buffer active, add the following global keybinding. Add this to send status updates

(global-set-key "\C-cip" 'identica-update-status-interactive)


Add this to send direct messages

(global-set-key "\C-cid" 'identica-direct-message-interactive)

Use

To start identica mode type:

M-x identica-mode


the buffer ‘*identica*’ will appear and you can see your friends timeline.

Press the “i” key to toggle icon mode to see user pictures.

Identica Emacs mode

To view your replies timeline

C-c C-r


To view the public timeline

C-c C-a


To view your friends timeline (the default timeline)

C-c C-f


To view a user’s timeline

C-c C-u


To view a group’s timeline

C-c C-g


To view a tag’s timeline

C-c C-t

To refresh the buffer’s timeline press “g”.

To post an update of your status, press

C-c C-s


type your message in the minibuffer, and hit Enter. You will see ‘Success: Post’ in minibuffer.

Identica mode for Emacs - Update status

To send a direct message to a user, press

C-c C-d


On the minibuffer, you will be prompted for the username, then for the message.

To repeat (re-dent) a message, press

C-c RET

while the cursor is on the message’s line.

To favor a message, press the “F” key (shift f) while the cursor is on the message’s line.

Additionally, you while typing your message you can press <F4> key while the cursor is over a URL to shorten it using any of the following URL shortening services: Ur1.ca, TightURL, Goo.gl, TinyURL, To.ly and Is.gd. To expand an short url in your timeline, position your cursor over the short url and press ‘e’ key, it will be replaced with the expanded version in a few seconds.

Hope it can be of use for anyone using Emacs for almost everything, like I try to do, and would like to hear some feedback.

Contribute

If you have any ideas for features, patches or bug fixes, please add them to the identica-mode bug tracking list.

You can also help out if you’ve liked Emacs identica-mode and have some spare change. It would be great to support this project by making any kind of donation on the “tip jar” in appreciation of the hours invested on its development and improvement.





Categories
Emacs GNU/Linux Free Software & Open Source

Emacs tip: How to edit multiple files on several directories in less than a minute

Recently I had to edit multiple files (239 in total) scattered in a bunch of directories and subdirectories. Here’s a quick and safe way to do it.

What I had to do was add the Google Analytics script snippet to a part of a website that was being maintained by a pair of <your favorite bad adjective here> developers.

So, first I thought of using sed or awk or something like that, but doing a quick search replace like that without checking if my match is correct in every instance in a bunch of files can lead to a big disaster.

But wait, I have Emacs! So, the first thing to do is find and list all the files you need to edit.

  1. Open the parent directory

    Use dired to open the parent directory where all the files and directories are. Open dired with:

    M-x find-dired


    and enter the path for the directory.

  2. Find the files

    Emacs will then prompt: “Run find (with args):”. So if you need to edit all HTML files, or in my case, PHP files, you type:

    -name "*.php"

    If you want all files regardless of type, enter

    -type f


    Basically you can type in any arguments you want if you know how to use the find command.

  3. Mark the files you need to edit

    A list of all found files will appear in a dired buffer. Now you need to mark the files you want to work with. Typically you’ll mark all files since you already filtered them. Press t to toggle marks and all files will get marked. Or if you want to hand pick them, move the cursor to the file line or name and press m.

  4. Do the find and replace

    Type: Press Q or M-x dired-do-query-replace-regexp to run the find and replace command. It will prompt you first for the text you want to find, then will prompt you with the text you want to replace it with.

    Then Emacs will start the find and replace operation, and will prompt you on every find if you want to replace the text or skip it. To replace, type y, to skip to the next find type n. To replace all occurrences without asking, type !. To cancel the operation, type C-g.

  5. Save the edited files

    Now that you’ve made all these changes, you need to save the files. To avoid saving manually all files, you can open ibuffer

    M-x ibuffer

    Which will list all you opened files (called buffers). Now, like in dired, you need to mark the buffers you want to work with. To mark all unsaved files, type * u and then type S (that’s shift+s, for the capital letter) to save them.

Done!

Easy and without a sweat.

photo by zyphichore on Flickr.

Categories
Emacs GNU/Linux Free Software & Open Source

PHP syntax error check as you type with Emacs

Emacs php syntax checking on the fly

For those who have to code in PHP, there’s a nice feature in Emacs that makes your coding horror times less stressing and helps you avoid typos and similar dumb errors. For example in the image above, I missed the colon at the end of the line.

Emacs 22.1 comes with flymake mode, a nice tool that makes syntax checking while you type out the file by highlighting the lines with errors and displays the error messages.

You can enable flymake to check PHP syntax by adding the following code on your .emacs or whatever Emacs customizations file you use:

;; Flymake PHP Extension
(require 'flymake)
(unless (fboundp 'flymake-php-init)
  (defun flymake-php-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
		       'flymake-create-temp-inplace))
	   (local-file (file-relative-name
			temp-file
			(file-name-directory buffer-file-name))))
      (list "php" (list "-f" local-file "-l")))))
(let ((php-ext-re "\\.php[345]?\\'")
      (php-error-re
       "\\(?:Parse\\|Fatal\\) error: \\(.*\\) in \\(.*\\) on line \\([0-9]+\\)"))
  (unless (assoc php-ext-re flymake-allowed-file-name-masks)
    (add-to-list 'flymake-allowed-file-name-masks
		 (list php-ext-re
                       'flymake-php-init
                       'flymake-simple-cleanup
                       'flymake-get-real-file-name))
    (add-to-list 'compilation-error-regexp-alist-alist
		 (list 'compilation-php
                       php-error-re  2 3 nil nil))
    (add-to-list 'compilation-error-regexp-alist 'compilation-php)
    (add-to-list 'flymake-err-line-patterns
		 (list php-error-re 2 3 nil 1))))
;; add php flymake support
(add-hook 'php-mode-hook (lambda () (flymake-mode t)))

Its very nice to have on the fly syntax checking.

Categories
Emacs GNU/Linux Free Software & Open Source

ACM Crossroads issue 14.4 online fast, thanks to Emacs

ACM Crossroads 14.4 cover

Just finished publishing ACM Crossroads issue 14.4 online.

This speed of publishing is thanks to Emacs. I use tramp mode to edit and fix files remotely on the ACM servers via ssh. Tidy with html-mode to validate and fix all markup so that the files are XHTML 1.1 Strict. Dired mode to rename, move, copy files, and image mode to check if images are correct.

I wonder if I can edit images (like crop, resize, convert to jpeg, compress) in Emacs. I know you can edit videos, so images can’t be more difficult.