Tuesday, June 4, 2013

emacs javasscript

(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))

(eval-after-load 'js2-mode '(progn
                              (require 'js-beautify)

                              (add-to-list 'load-path "~/.emacs.d/jquery-doc.el")
                              (require 'jquery-doc)
                              (require 'flymake-jshint)

                              (add-hook 'js2-mode-hook '(lambda ()
                                                          (flymake-mode 1)
                                                          (local-set-key "\M-t" 'js-beautify)
                                                          (define-key js2-mode-map [(shift f10)]  (lambda()(interactive)(jslint-thisfile)))))

                              (eval-after-load 'js2-mode
                                   (define-key js2-mode-map (kbd "TAB") (lambda()
                                                                          (let ((yas/fallback-behavior 'return-nil))
                                                                            (unless (yas/expand)
                                                                              (if (looking-back "^\s*")

                              ;; javascript lint 
                              (defun jslint-thisfile ()
                                (compile (format "jsl -process %s" (buffer-file-name))))

                              (require 'js-comint)
                              ;; Use node as our repl
                              (setq inferior-js-program-command "node")
                              (setq inferior-js-mode-hook
                                    (lambda ()
                                      ;; We like nice colors
                                      ;; Deal with some prompt nonsense
                                      (add-to-list 'comint-preoutput-filter-functions
                                                   (lambda (output)
                                                     (replace-regexp-in-string ".*1G\.\.\..*5G" "..."
                                                                               (replace-regexp-in-string ".*1G.*3G" ">" output))))))


(provide 'rgr-javascript)

Tuesday, March 12, 2013

Informative bash prompt

I hop between machines a lot at home. I want to know their IP address easily in addition to history count, user, and (if available) git branch in my .basrg
export PS1='($IP) [\!]\[\033[00;32m\]\u\[\033[01m\]@\[\033[00;36m\]\h\[\033[01m\]:\[\033[00;35m\]\w\[\033[00m\]\[\033[01;33m\]`git branch 2>/dev/null|cut -f2 -d\* -s`\[\033[00m\]\$ '

Monday, August 20, 2012

Loading jquery/javascript libraries from CDN if online etc local

I added some local flags too to enforce local loading : if they're not present then normal offline/online checks are done on the first library in the onlineJavaScriptLibs array. Short and sweet. See the code image here. I realise that the test for the first jquery lib using fopen doesnt gaurentee the others are there but if thats not there there are worse things. I could check for each and every library but meh. Even then php pass doesnt really guarentee the client can access the online library. The fopen checks looking for offlinejs work on a per web (custom/offlinejs) or on an all web (lib/offlinejs) and is really there for people testing/running my framework using a local code base where they might be offline. I had tried the method of loading jquery and then checking in javascript if window.jQuery was defined but simply couldnt get the document.write() method working : I then tried using jquery to append newly constructed script/link objects to body for the offline/onlie scripts but , well, it simply didnt work. Work effort v covenience v results.

Tuesday, February 14, 2012

de-mothballing my Thinkpad T60

I switched on my T60 last night : it hasnt been used since May 2011. Some
maintenance required. Amazingly the Linux way was so SO much quicker despite
more needing to be done : it having a lot more config changes to put it
inline with my netbook. The Debian installation first needed to be upgraded :
sudo aptitude update, sudo aptitude upgrade. It took about an hour to download
and install the huge amount of upgrades to Debian Squeeze since May. It worked
I then had to install Dropbox, sync it and link all my bash type control files
to the Dropbox equivalents. That took about 45 minutes. This included all GnuPG
data for secure encryption etc. Worked fine.
Finally clone the GIT repo containing various web stuff and restore the MySQL
databases : that took 2 minutes.
Restarted (there were new kernels installed too) and .. worked flawlessly.
Alas, Windows XP : nothing much to do per se (I dont do any development on it
and its usually just an iTunes host) but it needed 5 reboots and only after each
reboot did it then decide various other pakages needed upgrading. It took 5
hours with NO system reconfig on my part. Even now it takes 3x longer to be
ready to work on after booting up.

My Emacs Files At GitHub

Wednesday, October 12, 2011

ido-mode and virtual buffers

Every now and again you come across something in Emacs and slap your forehead and say "why didn't I notice that before". ido-mode is one, but the setting ido-use-virtual-buffers really makes it. The concept is simple : ido-mode remembers all your past buffers so all you need to do is "C-x b" (ido-switch-buffer) and start to type the filename and ido will complete to it having remembered it from previous sessions. No need to use C-x C-f and possibly the ido find facility any more - just type the mainpart of the filename or part of it. Incredible cool time saver and very very useful.

From the Manual

ido-use-virtual-buffers is a variable defined in `ido.el'.
Its value is t
Original value was nil

If non-nil, refer to past buffers as well as existing ones.
Essentially it works as follows: Say you are visiting a file and
the buffer gets cleaned up by mignight.el. Later, you want to
switch to that buffer, but find it's no longer open. With
virtual buffers enabled, the buffer name stays in the buffer
list (using the `ido-virtual' face, and always at the end), and if
you select it, it opens the file back up again. This allows you
to think less about whether recently opened files are still open
or not. Most of the time you can quit Emacs, restart, and then
switch to a file buffer that was previously open as if it still
This feature relies upon the `recentf' package, which will be
enabled if this variable is configured to a non-nil value.

my ido settings are currently:-

 '(ido-create-new-buffer (quote never))
'(ido-enable-flex-matching t)
'(ido-enable-last-directory-history nil)
'(ido-enable-regexp nil)
'(ido-max-directory-size 300000)
'(ido-max-file-prompt-width 0.1)
'(ido-use-filename-at-point (quote guess))
'(ido-use-url-at-point t)
'(ido-use-virtual-buffers t)

Wednesday, October 5, 2011

Javascript utilities

Playing with javascript lately I came across a super utility called jshint : and Dale Harvey has produced a super jshint-mode! For a javascript nOOb like me it's invaluable when combined with jslint (jshint can replace it, but you might like to turn it off at times then manually invoke jslint instead).

See : jshint and Javascript Lint

My javascript set up:-

(require 'js-beautify)

(add-to-list 'load-path "~/.emacs.d/jquery-doc")
(require 'jquery-doc)
(add-hook 'js2-mode-hook 'jquery-doc-setup)
(require 'flymake-jshint)
(add-hook 'js2-mode-hook
(lambda () (flymake-mode t)))

(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

;; (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-hook 'js2-mode-hook '(lambda () (js-beautify)(define-key js2-mode-map (kbd "M-t") (lambda()(interactive)(js-beautify)))(define-key js2-mode-map [(shift f10)] (lambda()(interactive)(jslint-thisfile)))))

;; javascript lint
(defun jslint-thisfile ()
(compile (format "jsl -process %s" (buffer-file-name))))
(defun jslint-thisfile-test ()
(compile (format "jsl -process %s" (buffer-file-name))))

(provide 'rgr-javascript)