With a little side of applesauce...

Thursday, October 27, 2011

EMACS - Coldfusion keyboard shortcuts

Here are some Coldfusion keyboard shortcuts that I use in EMACS to speed up my development. Throw these in your .emacs and M-x load-file:

;;;;;;;;
;; coldfusion
;;;;;;;;

(defun insert-cfdump-tag ()
"Insert cf markup <cfdump var='' />."
(interactive)
(insert "<cfdump var='##' />")
(backward-char 5)
)
(defun insert-cfabort-tag ()
"Insert cf markup <cfabort />."
(interactive)
(insert "<cfabort />")
)
(defun insert-cfcomment-tag ()
"Insert CF comment."
(interactive)
(insert "<!--- --->")
(backward-char 5)
)
(defun insert-cfoutput-tag ()
"Insert CFoutput."
(interactive)
(insert "<cfoutput>##</cfoutput>")
(backward-char 12)
)
(defun insert-cfparam-tag ()
"Insert CFparam."
(interactive)
(insert "<cfparam name='' default='' />")
(backward-char 15)
)
(defun insert-cfset-tag ()
"Insert CFset."
(interactive)
(insert "<cfset />")
(backward-char 3)
)
(defun insert-cflocation-tag ()
"Insert CFlocation."
(interactive)
(insert "<cflocation url='' addtoken='no' />")
(backward-char 17)
)
(defun insert-cftry-tag ()
"Insert CFtry."
(interactive)
(insert "<cftry>\n\n<cfcatch type="Any">\n\n</cfcatch>\n</cftry>")
(backward-char 42)
)
(defun insert-cfbreak-tag ()
"Insert cf markup <cfbreak />."
(interactive)
(insert "<cfbreak />")
)
(defun insert-cfobject-tag ()
"Insert CFobject."
(interactive)
(insert "<cfobject name='' component='' />")
(backward-char 17)
)
(defun insert-cfquery-tag ()
"Insert CFquery."
(interactive)
(insert "<cfquery datasource='' name=''>\n\n</cfquery>")
(backward-char 24)
)
(defun insert-cfqueryparam-tag ()
"Insert CFqueryparam."
(interactive)
(insert "<cfqueryparam value='##' cfsqltype='cf_sql_varchar'>,")
(backward-char 31)
)
(defun insert-cfvariable-tag ()
"Insert CF ##."
(interactive)
(insert "##")
(backward-char 1)
)
(defun insert-cfargument-tag ()
"Insert cfargument."
(interactive)
(insert "<cfargument name='' type='string' required='true' />")
(backward-char 34)
)
(defun insert-cffunction-tag ()
"Insert cffunction."
(interactive)
(insert "<cffunction name=''\nreturntype=''\naccess='public'\nhint=''\n>\n\n</cffunction>")
(backward-char 56)
)
(defun insert-cfcomponent-tag ()
"Insert cfcomponent."
(interactive)
(insert "<cfcomponent name=''\ndisplayname=''\nhint=''\n>\n\n</cfcomponent>")
(backward-char 42)
)
(defun insert-cfloop-tag ()
"Insert cfloop list."
(interactive)
(insert "<cfloop >\n\n</cfloop>")
(backward-char 12)
)
(defun insert-cfinclude-tag ()
"Insert cfinclude."
(interactive)
(insert "<cfinclude template='' />")
(backward-char 4)
)
; define some keys only when the major mode html-mode is active
(add-hook 'nxhtml-mode-hook
(lambda ()
(local-set-key (kbd "C-S-d") 'insert-cfdump-tag)
(local-set-key (kbd "C-S-a") 'insert-cfabort-tag)
(local-set-key (kbd "C-S-t") 'insert-cftry-tag)
(local-set-key (kbd "C-S-m") 'insert-cfcomment-tag)
(local-set-key (kbd "C-S-o") 'insert-cfoutput-tag)
(local-set-key (kbd "C-S-p") 'insert-cfparam-tag)
(local-set-key (kbd "C-S-s") 'insert-cfset-tag)
;(local-set-key (kbd "C-S-n") 'insert-cflocation-tag)
(local-set-key (kbd "C-S-b") 'insert-cfbreak-tag)
(local-set-key (kbd "C-S-i") 'insert-cfinclude-tag)
(local-set-key (kbd "C-S-q") 'insert-cfquery-tag)
(local-set-key (kbd "C-S-u") 'insert-cfqueryparam-tag)
(local-set-key (kbd "C-S-v") 'insert-cfvariable-tag)
(local-set-key (kbd "C-S-g") 'insert-cfargument-tag)
(local-set-key (kbd "C-S-f") 'insert-cffunction-tag)
(local-set-key (kbd "C-S-c") 'insert-cfcomponent-tag)
(local-set-key (kbd "C-S-l") 'insert-cfloop-tag)
)
)



This relies on nxhtml mode, which I download into ~/Documents/emacs and load with the following in my .emacs:

(load "~/Documents/emacs/nxhtml/autostart.el")


Also, you can tell EMACS to use nxhtml-mode for cfm and cfc files with this:
    (add-to-list 'auto-mode-alist '("\\.cfm\\'" . nxhtml-mode))
(add-to-list 'auto-mode-alist '("\\.cfc\\'" . nxhtml-mode))

No comments: