Posts

Take Charge of PDF in GNU Emacs

Image
Display popup annotation in docview   All or None Docview is the default major-mode for displaying PDF in Emacs. It converts each page into an image using ghostscript into a temporary folder (/tmp/docview<nnnn>) and displays the same. For large PDF document, this conversion is unnecessary in most cases - especially when one is looking at the document for quick reference.   An ideal solution would be to convert pages on demand. However, for this, one would need to know the number of pages in the document. This can be done either by some external tools like pdfinfo or one would need to parse the metadata in the document. So here's some elisp code for the same.   (require 'pdf) (pdf-get "Root.Pages.Count")   or   M-x pdf-total-pages   ;; Metadata about the document (pdf-get "Root.Metadata")     So here we are - now that one can parse the metadata, what else can we do? Form fields and Embedded scripts M-x pdf-form PDF supports embedded Javascr...

AWS API Usage in Elisp

Image
Here's some sample elisp code for signing Amazon Web Services (AWS) API requests . The value (first element) returned by (aws-sign4) is used in Authorization header while making a request. When the function is called with an expires value, it returns a URL which can be directly used in a browser. (require 'aws-sign4)   (let ((*aws-credentials*        (lambda ()          (values "AKIAIOSFODNN7EXAMPLE" "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"))))   (aws-sign4 :region "eu-west-1"              :service "s3"              :host "s3-eu-west-1.amazonaws.com"              :path "/some-bucket/some-file"              ))   (let ((*aws-credentials*      ...

One-click Social Media Client

Image
Reddit: Dashboard and details view Twitter: Dashboard and details view Tumblr: Dashboard and details view Youtube: Dashboard and details view   GNU Emacs as a Social Media Client Consumption of social media typically necessitates few repeated actions - like, share, comment and follow. If these actions are assigned to convenient keyboard keys, the consumption becomes easier - no more pointing and clicking tiny icons. Here's an attempt to unify this experience using GNU Emacs, tumblesocks and oauth2.   (require 'tumblesocks) (require 'oauth2)   ;; service below is one of twitter, reddit or tumblr (setq tumblesocks-service-conf    (service . ( client-id secret-key redirect-url ))     Use M-x sm-twitter , M-x sm-reddit , M-x sm-youtube or M-x sm-tumblr . First time, it will open a browser window. You'll need to login to the service and allow the permissions in following window. Then you'll be redirected to a URL. You'll need to copy the code (code= value...

Oauth2 sample flow in Elisp

Image
Here's a modified version of oauth2.el . This Elisp code works for oauth2 flow using Twitter, Gmail, Reddit and Tumblr. To add more services, add the provider URLs to the variable oauth2-service-conf. To make API calls, set the service configuration values (client-id, secret-key and  redirect-url) in the variable t-service-conf. Then use the examples in the usage section. (require 'oauth2)  (setq t-token nil) (setq t-service-conf   '((service . ( client-id secret-key redirect-url ))))   (defun t-api-oauth2-request (url params method service auth-scope                        &optional headers)   (let* ((oauth2-conf (assoc service oauth2-service-conf))      (conf (assoc service t-service-conf))      (t-consumer-key (nth 1 conf))      (t-secret-key (nth 2 conf))      (t-callback-url (nth 3 conf))      ...

Tumblr access from GNU Emacs

Image
Dashboard view (left) and detail view (right) tumblesocks-mode allows you to access Tumblr from GNU Emacs. Best part is - it has pagewise navigation by default instead of endless scroll. Use c for new post, f for follow, l for like and r for reblog. Since the repository is dormant and I needed some customization, I created a fork . It includes some UI changes, fix for emoji display, shorter tumblesocks alias and fix for displaying post at point, like post, reblog post, goto page etc.  

Compose Emoji in GNU Emacs

Image
  Modern emojis are composable - you can compose multiple emojis into a new one. Most commonly, this is done using Zero-Width Joiner or ZWJ character (#200D). Though not all combinations are valid. The valid combinations are defined by the font. e.g. you can combine as follows: Person + rocket = Astronaut Person + manual wheelchair = Person on wheelchair Following function will help you insert ZWJ in between selected text. (defun emoji-compose ()   "Compose emoji from components."   (interactive)   (unless (region-active-p)     (error "Select a sequence of emoji components"))   (let* ((start (1+ (region-beginning)))      (len (- (region-end) start)))     (goto-char start)     (dotimes (i len)       (insert #x200D)       (forward-char)))) For auto-completion, you can use company-emoji . References Unicode defined ZWJ sequences Unicode ZWJ specification ...

Comics Builder in GNU Emacs

Image
  Generate comics strip from a script in GNU Emacs. First, create a folder containing artwork. You can use samples from [2]. It should have three subfolders - faces, poses and backgrounds. Images can be GIF, JPG or PNG. Filenames for face and poses follow a convention: <id>-<emotion>.<ext> . Please ensure you have atleast one file for neutral emotion . Set appropriate values for following variables: comics-artwork - Folder containing artwork comics-col-max - Maximum no. of columns (default: 2) comics-emotions - Alist of emotions and words used to describe them comics-avatars - A list of cons cells (FACE-ID . BODY-ID) Open a file containing the script (sample below) and run M-x comics. This will generate an SVG image for the comics strip which will fit the display window. Panels are rendered with fixed font-size so that it is always readable. Actors are assigned an avatar from comics-avatars sequentially as they appear in the script. Normally, all the actors are d...