Pages

Friday, September 17, 2010

Thursday, September 16, 2010

Store existing blogger labels in org item created by the blog search functionality


Updated the list blog functionality to read back the tags from the
blogger entry and add them to the newly created org mode item in case
you cant to refile.




MyUpload.org


(global-set-key (kbd "C-c L") 'googlecl-list-blogs)

(defun googlecl-list-process (proc string)
(with-current-buffer (process-buffer proc)
(delete-region (point-min) (point-max))
(org-mode)
(org-insert-heading)
(insert(format " List of blogs with <%s> in the title\n\n" googlecl-default-title-filter))
(setq string (replace-regexp-in-string "\n$" "" string))
(save-excursion
(let ((items (split-string string "\n"))
(first t))
(while items
(let((item (pop items)))
(org-insert-heading)
(string-match "\\(.*\\),\\(http.*\\),\\(.*\\)$" item)
(insert (format "%s\n %s" (match-string 1 item)(match-string 2 item)))
(let ((taglist (split-string (match-string 3 item) ";")))
(if taglist (org-set-tags-to (add-to-list 'taglist googlecl-blog-tag))))
(if first (progn
(setq first nil)
(org-back-to-heading)
(org-metaright)
(org-end-of-subtree))))))))
(switch-to-buffer (process-buffer proc)))

(defun googlecl-list-blogs ()
"accept a title filter value and then list all blogs which match that value"
(interactive)
(let*((regexpfilter (read-from-minibuffer "Title Contains:" googlecl-default-title-filter) )
(listblogcmd (concat "google blogger list title,url,tags --title \"" regexpfilter "\"")))
(setq googlecl-default-title-filter regexpfilter)
(message "List blog command is : %s" listblogcmd)
(set-process-filter (start-process-shell-command "googlecl-list" "*googlcl blogs*" listblogcmd) 'googlecl-list-process)))




--
My Emacs Files At GitHub

List all blogger blogs whose titles match a regular expression

Added support to list all blogs containing certain regexp.
Create an org-mode buffer so you can refile links etc.

Original code here



(global-set-key (kbd "C-c L") 'googlecl-list-blogs)

(defun googlecl-list-process (proc string)
(with-current-buffer (process-buffer proc)
(delete-region (point-min) (point-max))
(org-mode)
(org-insert-heading)
(insert(format " List of blogs with <%s> in the title\n\n" googlecl-default-title-filter))
(setq string (replace-regexp-in-string "\n$" "" string))
(save-excursion
(let ((items (split-string string "\n"))
(first t))
(while items
(org-insert-heading)
(insert (replace-regexp-in-string ",http:" "\n http:" (pop items)))
(org-set-tags-to googlecl-blog-tag)
(if first (progn
(setq first nil)
(org-back-to-heading)
(org-metaright)
(org-end-of-subtree)))))))
(switch-to-buffer (process-buffer proc)))

(defun googlecl-list-blogs ()
"accept a title filter value and then list all blogs which match that value"
(interactive)
(let*((regexpfilter (read-from-minibuffer "Title Contains:" googlecl-default-title-filter) )
(listblogcmd (concat "google blogger list title,url --title \"" regexpfilter "\"")))
(setq googlecl-default-title-filter regexpfilter)
(message "List blog command is : %s" listblogcmd)
(set-process-filter (start-process-shell-command "googlecl-list" "*googlcl blogs*" listblogcmd) 'googlecl-list-process)))




--
My Emacs Files At GitHub

Using buffer narrowing in Emacs


Article about using buffer narrowing at the emacs-fu blog.
Very useful.
Emacs Manual : narrowing.
As a side note, emacs-fu is an awesome emacs resource.


--
My Emacs Files At GitHub

Last change navigation in Emacs


This is pretty good. Allows you to track back though the last places you altered.




(autoload 'goto-last-change "goto-last-change"
"Set point to the position of the last change." t)
(global-set-key (kbd "C-x C-n") 'goto-last-change)




--
My Emacs Files At GitHub

Sheeva plug : the idle web server


Wonderful devices : http://en.wikipedia.org/wiki/SheevaPlug



Small, cheap to run, headless, support Debian. Reliable I guess.


--
My Emacs Files At GitHub

Different color themes depending on windows or terminal


http://emacs-fu.blogspot.com/2009/03/color-theming.html




(require 'color-theme)
(require 'zenburn)
(color-theme-initialize)

(defvar after-make-console-frame-hooks '()
"Hooks to run after creating a new TTY frame")
(defvar after-make-window-system-frame-hooks '()
"Hooks to run after creating a new window-system frame")
(defun run-after-make-frame-hooks (frame)
"Selectively run either `after-make-console-frame-hooks' or
`
after-make-window-system-frame-hooks'"
(select-frame frame)
(run-hooks (if window-system
'after-make-window-system-frame-hooks
'after-make-console-frame-hooks)))
(add-hook 'after-make-frame-functions 'run-after-make-frame-hooks)
(add-hook 'after-init-hook
(lambda ()
(run-after-make-frame-hooks (selected-frame))))
(set-variable 'color-theme-is-global nil)
(add-hook 'after-make-window-system-frame-hooks 'color-theme-zenburn)
(add-hook 'after-make-console-frame-hooks 'color-theme-zenburn)





--
My Emacs Files At GitHub

Wednesday, September 15, 2010

Using the googlecl


http://groups.google.com/group/googlecl-discuss/browse_thread/thread/5bee204f9fe677ca


-----------------


Depends on the task. The "add" task follows quick-add text
rules:
http://www.google.com/support/calendar/bin/answer.py?answer=36604#text
<http://www.google.com/support/calendar/bin/answer.py?answer=36604#text>Setting
reminders is done with the --reminder option.
Dates of events to retrieve from the server (for listing, deleting, etc.)
uses the --date option

In general, if you're having trouble with the usage, check the following
docs:
Manual: http://code.google.com/p/googlecl/wiki/Manual
<http://code.google.com/p/googlecl/wiki/Manual>FAQ / troubleshooting:
http://code.google.com/p/googlecl/wiki/FAQ
<http://code.google.com/p/googlecl/wiki/FAQ>Configuration file help:
http://code.google.com/p/googlecl/wiki/ConfigurationOptions

<http://code.google.com/p/googlecl/wiki/ConfigurationOptions>For example,
the manual has a section on Calendar, and at the end, a section on how to
use --date.

If anything is unclear or confusing, just let the mailing list know, and
we'll clear it up or fix the docs.

----------------


--
My Emacs Files At GitHub

org-googlecl release version - support tagging of blogged entries


GitHub : Tag blogged org entries with googlecl-blog-tag if its set. Auto delete suppport via googlecl-blog-auto-del.


--
My Emacs Files At GitHub

Ooo! Feedback on org-googlecl


Its always nice to get some feedback.





Subject: Re: org-googlecl : enhancements - replace existing blog entries.
From: Tim Burt <tcburt@rochester.rr DOT MOC>
Date: Wed, 15 Sep 2010 05:56:32 -0400

Richard Riley <rileyrg@gmail.com> writes:

> The org-googlecl package has been extended a little.
>
> http://splash-of-open-sauce.blogspot.com/2010/09/now-org-googlecl-supports-deleting-of_14.html
>
> It now detects if you try to blog an entry with the same title as an
> existing one and prompts you to view and/or remove one or more entries
> with the same name. Obviously very useful for just updating an entry (NB
> the url will change unfortunately). There is also a footer option and
> default labels (tags) if none are specified on the org entry you are
> blogging.

Tags as labels for the blog is a welcome feature.

> It's working pretty cleanly now but any feedback appreciated -
> its a pretty handy complement to org-mode if you maintain a
> blogger/blogspot account.

That's an understatement. Publishing from org to blogger is nearly
transparent and takes only seconds to confirm the information
(e.g. title, labels). It is a treat to use org-googlecl. Thank you
Richard.

Tim

> The elisp snippets you will see above were all
> blogged from my dotemacs files which are all in org files using this
> function.
>
> regards
>
> r.
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode





--
My Emacs Files At GitHub

Example of providing auto input to a waiting shell process


In this instance pipes "y" to the called process to confirm we want the blog deleted.




(let ((delcommand  (format "yes y | google blogger delete --blog '%s'  --title '%s'"  googlecl-blogname  btitle)))
(message "Delete command is : %s" delcommand)
(call-process-shell-command delcommand))




--
My Emacs Files At GitHub

Tuesday, September 14, 2010

Now org-googlecl supports deleting of existing entries


If you try to blog a title that exists you can examine it and/or
delete prior to blogging the new version. See link in footer for git
files.





(if googlecl-blog-exists
(with-temp-buffer
(let* ((blogrc (call-process-shell-command (concat "google blogger list --blog '" googlecl-blogname "' --title '" btitle "' url") nil (current-buffer)))
(blogurl (buffer-string)))
(if (not (zerop(length blogurl)))
(progn
(if (y-or-n-p (concat "Blog entry exists :" blogurl ". View existing?"))
(browse-url (nth 0 (org-split-string blogurl))))
(setq blogurl (nth 0 (org-split-string blogurl)))
(if (y-or-n-p "Delete existing blog entry?")
(let ((delcommand (format "yes y | google blogger delete --blog '%s' --title '%s'" googlecl-blogname btitle)))
(message "Delete command is : %s" delcommand)
(call-process-shell-command delcommand))))))))




--
My Emacs Files At GitHub

Multiple Tabs (Elscreen)

(require 'elscreen) ;; C-z n for new screen or next etc.
(require 'elscreen-gf) ;; C-z n for new screen or next etc.

(defmacro elscreen-create-automatically (ad-do-it)
`(if (not (elscreen-one-screen-p))
,ad-do-it
(elscreen-create)
(elscreen-notify-screen-modification 'force-immediately)
(elscreen-message "New screen is automatically created")))

(defadvice elscreen-jump (before elscreen-jump-create activate)
(let ((next-screen (string-to-number (string last-command-event))))
(when (and (<= 0 next-screen)
(<= next-screen 9)
(not (elscreen-screen-live-p next-screen)))
(elscreen-set-window-configuration
(elscreen-get-current-screen)
(elscreen-current-window-configuration))
(elscreen-set-window-configuration
next-screen (elscreen-default-window-configuration))
(elscreen-append-screen-to-history next-screen)
(elscreen-notify-screen-modification 'force))))

(defadvice elscreen-next (around elscreen-create-automatically activate)
(elscreen-create-automatically ad-do-it))

(defadvice elscreen-previous (around elscreen-create-automatically activate)
(elscreen-create-automatically ad-do-it))

(defadvice elscreen-toggle (around elscreen-create-automatically activate)
(elscreen-create-automatically ad-do-it))




EMMS music setup using mpd

(define-key mode-specific-map (kbd "e e") 'my-start-player)
(require 'emms-source-file)
(require 'emms-player-mpd)
(require 'emms-playing-time)
(require 'emms-playlist-mode)
(require 'emms-mode-line-icon)
(require 'emms-streams)
(require 'emms-stream-info)
(require 'emms-volume)

(require 'emms-setup)
(emms-devel)
(emms-mode-line 1)
(emms-playing-time 1)

(emms-player-set emms-player-mpd 'regex
"\\.ogg\\|\\.mp3\\|\\.wma\\|\\.ogm\\|\\.asf\\|\\.mkv\\|http://\\|mms://\\|\\.rmvb\\|\\.flac\\|\\.vob\\|\\.m4a\\|\\.ape\\|\\.mpc")
(emms-player-set emms-player-mplayer 'regex
"\\.wav\\|\\.pls+\\|\\.mpg\\|\\.mpeg\\|\\.wmv\\|\\.wma\\|\\.mov\\|\\.avi\\|\\.divx\\|\\.ogm\\|\\.asf\\|\\.mkv\\|.rm\\|\\.rmvb\\|\\.mp4|\\.rm")


(define-emms-combined-source all nil
'((emms-source-directory emms-source-file-default-directory)))

(setq emms-playlist-buffer "*Music*")

;;;###autoload
(defun rgr/track-search()
(interactive)
(anything (list anything-c-source-emms-file anything-c-source-emms-directory anything-c-source-emms-playlist) nil "Video or even some music Sir? ")
)

(defadvice rgr/track-search (after rgr/track-search) (run-at-time "2 sec" nil 'emms-player-mpd-connect))


;;(add-hook 'emms-player-started-hook 'emms-player-mpd-connect)
(setq emms-show-format "EMMS is now playing : %s")

;; get list back from mpd for proper formatting
;; (defadvice emms-play-file (after emms-play-file activate)
;; (emms-player-mpd-connect))

; (emms-lyrics 1)
; (emms-lyrics-ena1ble)

(emms-playing-time 1)
(emms-mode-line 1)

(require 'emms-extension)
(ad-unadvise 'emms-play-directory-tree)

(define-key mode-specific-map (kbd "e q") 'my-stop-player)

(define-key mode-specific-map (kbd "e D") 'emms-mode-line-toggle)

(define-key mode-specific-map (kbd "e R") 'my-emms-streams)

(define-key mode-specific-map (kbd "e c") 'emms-playlist-current-clear)

(define-key mode-specific-map (kbd "e d") (lambda() (interactive)(emms-play-dired)(my-start-player)))
(define-key mode-specific-map (kbd "e a") 'emms-add-dired)
(define-key mode-specific-map (kbd "e m") 'emms-play-matching)
(define-key mode-specific-map (kbd "e f") 'emms-add-find)
(define-key mode-specific-map (kbd "e b") 'emms-browser)
(define-key mode-specific-map (kbd "e s") 'emms-smart-browse)

(define-key mode-specific-map (kbd "e j") 'emms-seek)
(define-key mode-specific-map (kbd "e <right>") (lambda()(interactive)(emms-seek 30)))
(define-key mode-specific-map (kbd "e <left>") (lambda()(interactive)(emms-seek -15)))

(define-key mode-specific-map (kbd "e l") 'my-emms-switch-to-current-playlist)
(define-key mode-specific-map (kbd "e L") 'emms-play-playlist)

(define-key mode-specific-map (kbd "e n") 'emms-next)
(define-key mode-specific-map (kbd "e p") 'emms-previous)

(define-key mode-specific-map (kbd "e +") 'emms-volume-raise)
(define-key mode-specific-map (kbd "e -") 'emms-volume-lower)

(define-key mode-specific-map (kbd "e r") 'emms-random)

(define-key mode-specific-map (kbd "e <SPC>") 'emms-pause)

(defun my-emms-info-track-description (track)
"Return a description of the current track."
(if (and (emms-track-get track 'info-artist)
(emms-track-get track 'info-title))
(let ((pmin (emms-track-get track 'info-playing-time-min))
(psec (emms-track-get track 'info-playing-time-sec))
(ptot (emms-track-get track 'info-playing-time))
(art (emms-track-get track 'info-artist))
(tit (emms-track-get track 'info-title)))
(cond ((and pmin psec) (format "%s - %s " art tit ))
(ptot (format "%s - %s " art tit ))
(t (emms-track-simple-description track))))))

(defun my-stop-player ()
"Stop emms player."
(interactive)
(shell-command "mpd --kill")
(emms-playlist-current-kill)
(emms-player-mpd-disconnect))

;; Switch to the radio buffer
(defun my-emms-streams ()
(interactive)
(my-start-player)
(let ((buf (get-buffer emms-stream-buffer-name)))
(if buf
(switch-to-buffer buf)
(emms-streams))))

;; Switch to either the radio buffer or the current EMMS playlist
(defun my-emms-switch-to-current-playlist ()
(interactive)
(if (and (boundp 'emms-stream-playlist-buffer)
(eq emms-stream-playlist-buffer emms-playlist-buffer))
(switch-to-buffer emms-stream-buffer-name)
(if (or (null emms-playlist-buffer)
(not (buffer-live-p emms-playlist-buffer)))
(error "No current Emms buffer")
(switch-to-buffer emms-playlist-buffer))))


(defun my-start-player ()
"Start MPD and sync to its playlistemms player."
(interactive)
(shell-command "mpd") ; uses default ~/.mpdconf
(emms-player-mpd-connect)
(switch-to-buffer emms-playlist-buffer)
(global-set-key (kbd "<M-f1>") 'rgr/track-search)
)




Language translation utilities/helper functions for interfacing to Babel


If prefix the call to the translate function than store the translation as an org item.




(require 'babel)

(defvar rgr/learn-first-lesson 1)
(defvar rgr/orig-text "The text we wish to translate")
(defvar rgr/trans-text "The translated text")

(setq babel-echo-area t)
(setq babel-preferred-from-language "English")
(setq babel-preferred-to-language "German")


(defun rgr/babel-language-code (lang)
(cdr (assoc lang babel-languages)))

(defun rgr/translate( &optional usedef )
(interactive)
(let* ((default (region-or-word-at-point)))
(setq default
(read-string (format "Translate \"%s\" :" default) nil nil default))
(when (length default)
(setq rgr/trans-text (babel default nil usedef))
(setq rgr/orig-text default)
(if current-prefix-arg
(progn
(org-capture nil ?v)
(org-schedule nil (time-add (current-time) (days-to-time rgr/learn-first-lesson)))))
(rgr/notify rgr/trans-text) ;; calls gnome notify function or whatever.
(message "%s" rgr/trans-text))))

(defun rgr/toggle-languages()
(interactive)
(let* ((temp babel-preferred-to-language))
(setq babel-preferred-to-language babel-preferred-from-language
babel-preferred-from-language temp))
(message "%s to %s " babel-preferred-from-language babel-preferred-to-language))

(global-set-key (kbd "<f5>")
(lambda()
(interactive)(require 'babel)(rgr/translate t)))

(global-set-key (kbd "<f6>")
'rgr/toggle-languages)




Emailing or replying to someone using recipient specific from address


The BBDB can be used to store specific fields which tell Gnus which accounts to
use when posting to the recipient in the BBDB.





(defun DE-bbdb-match-field-recipient (field regexp)
"Match FIELD for recipient against REGEXP.
FIELD must be a symbol, e.g. 'email-type."

(debug)
(let (who rec)
(when (and
(gnus-buffer-live-p gnus-article-copy)
(setq who
(with-current-buffer gnus-article-copy
(save-restriction
(nnheader-narrow-to-headers)
(or (message-fetch-field "reply-to")
(message-fetch-field "from")))))
(setq rec
(bbdb-search-simple
nil
(cadr (gnus-extract-address-components who)))))
(string-match regexp (bbdb-get-field rec field)))))


;; by adding a bdbb field called "email-type" and setting it to "friend-alias"
;; this gnus-posting-style is met when replying to people. If posting from a group
;; with "friends" in the name ditto.
(add-to-list `gnus-posting-styles `((or (string-match ,(rx "friends") gnus-newsgroup-name) (DE-bbdb-match-field-recipient 'email-type "friend-alias"))
(from rgr/friends-email)
(name rgr/friends-name)
(organization nil)
(eval (setq mml2015-signers nil))
(signature-file "~/.emacs.d/.sigs/friends.sig")) t )




Google and URL Opening from Emacs

(autoload 'w3m-browse-url "w3m" nil t)
(autoload 'browse-url-interactive-arg "browse-url")

(require 'browse-apropos-url)
(require 'browse-url)
(require 'thingatpt+)
(require 'w3m)

(defun rgr/browse (url)
"If prefix is specified use the system default browser else use the configured emacs one"
(if current-prefix-arg
(if url
(w3m-browse-url url)
(call-interactively 'browse-url))
(when url (browse-url-generic url))
))

(defun rgr/browse-url (&optional url)
"browse the url passed in"
(interactive)
(setq url (or url (w3m-url-valid (w3m-anchor)) (browse-url-url-at-point) (region-or-word-at-point)))
(setq url (read-string (format "Url \"%s\" :" url) url nil url))
(rgr/browse url))

(defun rgr/browse-apropos-url (apropos-prefix prompt)
(interactive)
(let* ((default (region-or-word-at-point))
)
(setq default (read-string (format prompt default) default nil default))
(browse-apropos-url (concat apropos-prefix " " default) nil current-prefix-arg)))


(defun rgr/google-search-prompt (&optional default)
(interactive)
(let* ((default (or default (region-or-word-at-point)))
(term (read-string (format "Google.com the web for the following phrase (%s): "
default) nil nil default)))
(rgr/browse (concat "http://www.google.com/search?q=" ; borrowed from dim
(replace-regexp-in-string
"[[:space:]]+"
"+"
term)))))

; google keys and url keys
; prefix (ctl-u) to use external browser.
(global-set-key (kbd "<f4>") 'rgr/browse-url)
(global-set-key (kbd "<f3>") 'rgr/google-search-prompt)




Setting up Gnus to read local dovecot server and nntp news


See Gnus IMAP




(setq gnus-select-method '(nnml ""))

(add-to-list 'gnus-secondary-select-methods
'(nnimap "riley"
(nnimap-address "offlineimap")
(nnir-search-engine imap)
(nnimap-stream network)
(nnimap-authinfo-file "~/.authinfo.gpg")))

(add-to-list 'gnus-secondary-select-methods
'(nnimap "shamrockpub"
(nnimap-address "offlineimap")
(nnir-search-engine imap)
(nnimap-stream network)
(nnimap-authinfo-file "~/.authinfo.gpg")))

(add-to-list 'gnus-secondary-select-methods
'(nnimap "friends"
(nnimap-address "offlineimap")
(nnir-search-engine imap)
(nnimap-stream network)
(nnimap-authinfo-file "~/.authinfo.gpg")))


(add-to-list 'gnus-secondary-select-methods '(nntp "Gmane" (nntp-address "news.gmane.org")))
(add-to-list 'gnus-secondary-select-methods '(nntp "Gwene" (nntp-address "news.gwene.org")))
(add-to-list 'gnus-secondary-select-methods '(nntp "Gnus" (nntp-address "news.gnus.org")))


(setq gnus-posting-styles `((".*"
(name "Richard Riley")
(from "Richard Riley <rileyrg@googlemail.com>")
(eval(setq gnushush-user-agent-header (quote real)))
(signature-file "~/.emacs.d/.sigs/rgr.sig")
(eval (setq mml2015-signers '("AB23BE58")))
(organization "aich tea tea pea dicky riley dot net"))))



(setq mail-host-address "news.eternal-september.org")




Using dictem for word lookup and flyspell for interactive spell checking

(require 'dictem)

; SEARCH = MATCH + DEFINE
; Ask for word, database and search strategy
; and show definitions found
(global-set-key (kbd "C-c s") 'dictem-run-search)


; SHOW DB
; Show a list of databases provided by DICT server
(global-set-key "\C-c\M-b" 'dictem-run-show-databases)

(define-key dictem-mode-map [tab] 'dictem-next-link)
(define-key dictem-mode-map [(backtab)] 'dictem-previous-link)
(define-key dictem-mode-map [return] 'dictem-run-search)

(dictem-initialize)


;;;###autoload
(defun rgr/synonyms()
(interactive)
(let* ((default (region-or-word-at-point))
(term (read-string (format "Synonyms for (%s): "
default) default)))
(dictem-run
'dictem-base-search
"moby-thes" term "exact")))

(define-key mode-specific-map [?S] 'rgr/synonyms)

(dictem-initialize)

(add-hook 'dictem-postprocess-match-hook
'dictem-postprocess-match)

(add-hook 'dictem-postprocess-definition-hook
'dictem-postprocess-definition-separator)

(add-hook 'dictem-postprocess-definition-hook
'dictem-postprocess-definition-hyperlinks)

(add-hook 'dictem-postprocess-show-info-hook
'dictem-postprocess-definition-hyperlinks)

(add-hook 'dictem-postprocess-definition-hook
'dictem-postprocess-each-definition)

(require 'flyspell)

(define-key flyspell-mode-map (kbd "C-+") 'flyspell-check-previous-highlighted-word)
(define-key flyspell-mode-map (kbd "C-#") 'flyspell-auto-correct-previous-word)
(define-key flyspell-mode-map (kbd "S-<f2>") 'ispell-word)
(define-key flyspell-mode-map (kbd "C-<f2>") 'flyspell-auto-correct-previous-word)
(define-key flyspell-mode-map (kbd "<f2>") 'flyspell-auto-correct-word)

(define-minor-mode babel-permanent-translation-mode "Bable translate notext")

(define-key mode-specific-map [?o] (lambda()(interactive)(if (babel-permanent-translation-mode) (add-hook 'post-command-hook 'rgr/context-babel nil t)(remove-hook 'post-command-hook 'rgr/context-babel))))

(setq babel-echo-area t)
(setq babel-preferred-from-language "German")
(setq babel-preferred-to-language "English")

(defun turn-on-flyspell ()
"Force flyspell-mode on using a positive arg. For use in hooks."
(interactive)
(flyspell-mode 1))