Showing posts with label emacs. Show all posts
Showing posts with label emacs. Show all posts

Saturday, 11 November 2017

More pdf-tools tricks

Following a couple of recent postings on pdf-tools, here are a few customisations I've found handy.

For scanned pdfs, 'pdf-view-auto-slice-minor-mode can be useful to turn on. You might bind it to something like s a. It auto trims the borders for each page of the pdf as it encounters them.

The following sets up a variety of colour-filter modes (good for night-time viewing, or anytime really that you don't want your eyeballs blasted with blazing white light):

;; midnite mode hook
 (add-hook 'pdf-view-mode-hook (lambda ()
                                 (pdf-view-midnight-minor-mode))) ; automatically turns on midnight-mode for pdfs

(setq pdf-view-midnight-colors '("#ff9900" . "#0a0a12" )) ; set the amber profile as default (see below)

(defun bms/pdf-no-filter ()
  "View pdf without colour filter."
  (interactive)
  (pdf-view-midnight-minor-mode -1)
  )

;; change midnite mode colours functions
(defun bms/pdf-midnite-original ()
  "Set pdf-view-midnight-colors to original colours."
  (interactive)
  (setq pdf-view-midnight-colors '("#839496" . "#002b36" )) ; original values
  (pdf-view-midnight-minor-mode)
  )

(defun bms/pdf-midnite-amber ()
  "Set pdf-view-midnight-colors to amber on dark slate blue."
  (interactive)
  (setq pdf-view-midnight-colors '("#ff9900" . "#0a0a12" )) ; amber
  (pdf-view-midnight-minor-mode)
  )

(defun bms/pdf-midnite-green ()
  "Set pdf-view-midnight-colors to green on black."
  (interactive)
  (setq pdf-view-midnight-colors '("#00B800" . "#000000" )) ; green 
  (pdf-view-midnight-minor-mode)
  )

(defun bms/pdf-midnite-colour-schemes ()
  "Midnight mode colour schemes bound to keys"
        (local-set-key (kbd "!") (quote bms/pdf-no-filter))
        (local-set-key (kbd "@") (quote bms/pdf-midnite-amber)) 
        (local-set-key (kbd "#") (quote bms/pdf-midnite-green))
            (local-set-key (kbd "$") (quote bms/pdf-midnite-original))
 )  

(add-hook 'pdf-view-mode-hook 'bms/pdf-midnite-colour-schemes)


This automatically sets pdf-tools to display using the midnight mode amber filter.
You can return to the original/no-filter with "!" (i.e. S-1); set amber filter with "@" (i.e. S-2); set green filter with "#" (i.e. S-3); set the bluish original midnight mode colours with "$" (i.e. S-4). See below for screenshots of these different settings.







You also probably want to set the pdf-annot-default-markup-annotation-properties color to "#ff0000", as well as the pdf-annot-default-text-annotation-properties color to "#ff0000". This is a colour that is actually visible in the midnight-modes. If you go with the default yellow for markup it will not be easily visible in any of these colour-filter modes.

Sunday, 12 March 2017

Take Elfeed everywhere: Mobile rss reading Emacs-style (for free/cheap)

After the demise of Google Reader, I switched for some time to NewsBlur. Unfortunately, its Android app never worked well for me. And integrating more of my life into Emacs is always desirable, so once I saw there was an Android interface for the fantastic Emacs RSS reader Elfeed, I made the switch.

The tricky thing with the Elfeed Android client is that it wants to connect to web interface of an instance of Elfeed running inside of Emacs. I could have done with my home computer, but that would require poking a hole through the firewall and in any case would be non-ideal when for instance I was travelling.

About a month ago I hit upon a cheap (in fact, free) solution for running a remote instance of Emacs running Elfeed that is connectable with the Android app. The VPS provider Wishosting offers an OpenVZ mini for $4/year, and if you stick a link to Wishosting on your own domain you can get it for free.

On my home desktop, work desktop, and laptop, I have Syncthing installed and I use this to keep the Elfeed database in sync between these machines.

In this blogpost I outline how to add a remote always-on instance of Elfeed running in Wishosting’s OpenVZ mini which also remains in sync with all of the other machines. (I use elfeed-org to organise my feeds, and just keep the elfeed.org file in ~/.elfeed/.) Just use Syncthing to keep the ~/.elfeed directory sync’ed between all of the machines (including any VPS’s).

I set up an Ubuntu 16.04 LTS VPS on Wishosting, and then installed Emacs and Syncthing, and that is what I would recommend.

Steps
  • Create your Ubuntu 16.04 LTS VPS.
  • Make a (non-root) user with superuser capability. Login with this user.
  • Install Emacs and Syncthing.
  • Configure Syncthing appropriately. You can connect remotely to the Web GUI.
  • Create and save a .emacs file in your user’s ~ with the following contents:
    ;; package setup here
    (require 'package)
    
    (package-initialize nil)
    (setq package-enable-at-startup nil)
    
    (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
    
    (add-to-list 'package-archives
          '("melpa" . "https://melpa.org/packages/") t)
    
    (add-to-list 'package-archives
          '("marmalade" .
            "http://marmalade-repo.org/packages/"))
    
    (package-initialize)
    
    ;; general add packages to list
    (let ((default-directory  "~/.emacs.d/elpa/"))
      (normal-top-level-add-subdirs-to-load-path))
    
    ;; make sure 'use-package is installed
    (unless (package-installed-p 'use-package)
      (package-refresh-contents)
      (package-install 'use-package))
    
    ;;; use-package
    (require 'use-package)
    
    ;; Load elfeed
    (use-package elfeed
      :ensure t
      :bind (:map elfeed-search-mode-map
         ;              ("A" . bjm/elfeed-show-all)
         ;              ("E" . bjm/elfeed-show-emacs)
         ;              ("D" . bjm/elfeed-show-daily)
           ("q" . bjm/elfeed-save-db-and-bury)))
    
    (require 'elfeed)
    
    ;; Load elfeed-org
    (use-package elfeed-org
      :ensure t
      :config
      (elfeed-org)
      (setq rmh-elfeed-org-files (list "~/.elfeed/elfeed.org"))
      )
    
    ;; Laod elfeed-goodies
    (use-package elfeed-goodies
      :ensure t
      )
    
    (elfeed-goodies/setup)
    
    ;; Load elfeed-web
    (use-package elfeed-web
      :ensure t
      )
    
    ;;; Elfeed
    (global-set-key (kbd "C-x w") 'bjm/elfeed-load-db-and-open)
    
    (define-key elfeed-show-mode-map (kbd "j") 'elfeed-goodies/split-show-next)
    (define-key elfeed-show-mode-map (kbd "k") 'elfeed-goodies/split-show-prev)
    (define-key elfeed-search-mode-map (kbd "j") 'next-line)
    (define-key elfeed-search-mode-map (kbd "k") 'previous-line)
    (define-key elfeed-show-mode-map (kbd "S-SPC") 'scroll-down-command)
    
    
    ;;write to disk when quiting
    (defun bjm/elfeed-save-db-and-bury ()
      "Wrapper to save the elfeed db to disk before burying buffer"
      (interactive)
      (elfeed-db-save)
      (quit-window))
    
    ;;functions to support syncing .elfeed between machines
    ;;makes sure elfeed reads index from disk before launching
    (defun bjm/elfeed-load-db-and-open ()
      "Wrapper to load the elfeed db from disk before opening"
      (interactive)
      (elfeed-db-load)
      (elfeed)
      (elfeed-search-update--force)
      (elfeed-update))
    
    (defun bjm/elfeed-updater ()
      "Wrapper to load the elfeed db from disk before opening"
      (interactive)
      (elfeed-db-save)
      (quit-window)
      (elfeed-db-load)
      (elfeed)
      (elfeed-search-update--force)
      (elfeed-update))
    
    (run-with-timer 0 (* 30 60) 'bjm/elfeed-updater)
    
    (setq httpd-port NNNNN)   ; replace NNNNN with a port equalling your start port + 10 (or whatever)
    
    (elfeed-web-start)
    
Note that you’ll need to configure the httpd-port appropriately as per the comment in the elisp above.
  • Then create the following systemd unit at ~/.config/systemd/user/emacs.service:
[Unit]
Description=Emacs: the extensible, self-documenting text editor

[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Restart=always

[Install]
WantedBy=default.target
  • Enable and start this unit with:
$ systemctl --user enable --now emacs
  • And then make sure it runs persistently even when you’re not connected to your VPS via ssh (this tripped me up for some time):
# loginctl enable-linger USERNAME
  • Install the Elfeed Android app on your mobile, enter the app’s Settings, and put in whatever your Wishosting ip is plus the port you chose above (NNNNN), e.g. http://199.39.100.23:54169, for the Elfeed web url.
  • That should be it. Now you’ll have access to your rss feed all over the world and Syncthing will ensure that all changes will be propagated to all of your Emacs instances including your VPS. These changes would include adding and deleting rss feeds and marking of posts as ’read’.
  • Note: on my desktops/laptop I use the following setup for Elfeed:
    ;; Load elfeed
    (use-package elfeed
      :ensure t
      :bind (:map elfeed-search-mode-map
    ;              ("A" . bjm/elfeed-show-all)
    ;              ("E" . bjm/elfeed-show-emacs)
    ;              ("D" . bjm/elfeed-show-daily)
           ("q" . bjm/elfeed-save-db-and-bury)))
    
    
    (require 'elfeed)
    
    ;; Load elfeed-org
    (use-package elfeed-org
      :ensure t
      :config
      (elfeed-org)
      (setq rmh-elfeed-org-files (list "~/.elfeed/elfeed.org"))
      )
    
    ;; Laod elfeed-goodies
    (use-package elfeed-goodies
      :ensure t
      )
    
    (elfeed-goodies/setup)
    
    ;; Load elfeed-web
    (use-package elfeed-web
      :ensure t
      )
    
    ;;functions to support syncing .elfeed between machines
    ;;makes sure elfeed reads index from disk before launching
    (defun bjm/elfeed-load-db-and-open ()
      "Wrapper to load the elfeed db from disk before opening"
      (interactive)
      (elfeed-db-load)
      (elfeed)
      (elfeed-search-update--force)
      (elfeed-update))
    
    ;;write to disk when quiting
    (defun bjm/elfeed-save-db-and-bury ()
      "Wrapper to save the elfeed db to disk before burying buffer"
      (interactive)
      (elfeed-db-save)
      (quit-window))
    
    
    ;;; Elfeed
    (global-set-key (kbd "C-x w") 'bjm/elfeed-load-db-and-open)
    
    
    
    (define-key elfeed-show-mode-map (kbd ";") 'visual-fill-column-mode)
    
    (define-key elfeed-show-mode-map (kbd "j") 'elfeed-goodies/split-show-next)
    (define-key elfeed-show-mode-map (kbd "k") 'elfeed-goodies/split-show-prev)
    (define-key elfeed-search-mode-map (kbd "j") 'next-line)
    (define-key elfeed-search-mode-map (kbd "k") 'previous-line)
    (define-key elfeed-show-mode-map (kbd "S-SPC") 'scroll-down-command)
    
    ;; probably temporary: hack for elfeed-goodies date column:
    (defun elfeed-goodies/search-header-draw ()
      "Returns the string to be used as the Elfeed header."
      (if (zerop (elfeed-db-last-update))
          (elfeed-search--intro-header)
        (let* ((separator-left (intern (format "powerline-%s-%s"
            elfeed-goodies/powerline-default-separator
            (car powerline-default-separator-dir))))
        (separator-right (intern (format "powerline-%s-%s"
             elfeed-goodies/powerline-default-separator
             (cdr powerline-default-separator-dir))))
        (db-time (seconds-to-time (elfeed-db-last-update)))
        (stats (-elfeed/feed-stats))
        (search-filter (cond
          (elfeed-search-filter-active
           "")
          (elfeed-search-filter
           elfeed-search-filter)
          (""))))
          (if (>= (window-width) (* (frame-width) elfeed-goodies/wide-threshold))
       (search-header/draw-wide separator-left separator-right search-filter stats db-time)
     (search-header/draw-tight separator-left separator-right search-filter stats db-time)))))
    
    (defun elfeed-goodies/entry-line-draw (entry)
      "Print ENTRY to the buffer."
    
      (let* ((title (or (elfeed-meta entry :title) (elfeed-entry-title entry) ""))
      (date (elfeed-search-format-date (elfeed-entry-date entry)))
      (title-faces (elfeed-search--faces (elfeed-entry-tags entry)))
      (feed (elfeed-entry-feed entry))
      (feed-title
       (when feed
         (or (elfeed-meta feed :title) (elfeed-feed-title feed))))
      (tags (mapcar #'symbol-name (elfeed-entry-tags entry)))
      (tags-str (concat "[" (mapconcat 'identity tags ",") "]"))
      (title-width (- (window-width) elfeed-goodies/feed-source-column-width
        elfeed-goodies/tag-column-width 4))
      (title-column (elfeed-format-column
       title (elfeed-clamp
              elfeed-search-title-min-width
              title-width
              title-width)
       :left))
      (tag-column (elfeed-format-column
            tags-str (elfeed-clamp (length tags-str)
              elfeed-goodies/tag-column-width
              elfeed-goodies/tag-column-width)
            :left))
      (feed-column (elfeed-format-column
             feed-title (elfeed-clamp elfeed-goodies/feed-source-column-width
          elfeed-goodies/feed-source-column-width
          elfeed-goodies/feed-source-column-width)
             :left)))
    
        (if (>= (window-width) (* (frame-width) elfeed-goodies/wide-threshold))
     (progn
       (insert (propertize date 'face 'elfeed-search-date-face) " ")
       (insert (propertize feed-column 'face 'elfeed-search-feed-face) " ")
       (insert (propertize tag-column 'face 'elfeed-search-tag-face) " ")
       (insert (propertize title 'face title-faces 'kbd-help title)))
          (insert (propertize title 'face title-faces 'kbd-help title)))))
    
Screenshots:
[Also posted at r/emacs]

Sunday, 21 December 2014

Emacs and (synchronised) org-mode on Android

Running emacs and org-mode under Android. I’m doing this on my Android tablet - it’s not perhaps as useful on a phone, though it’s not unmanageable.

There used to be an Emacs app for Android in the Google Play store - in fact it’s still there, but the server it used to download its files from is no longer working - and the app was always a bit fiddly to get to work properly.

Here’s a better way of getting it working:
  • Install ZShaolin, a console terminal emulator (zsh shell) for Android with a number of useful commandline tools like rsync, awk, imagmagick etc.
  • Then install the files from the old Emacs app. They’re no longer accessible via the app from the Play store, but I had saved the files from back when it still worked, and have zipped them up and thrown them on mega: https://mega.co.nz/#!B4AThKxI!_ImT57mJNirozxna-1SOcNGAzPRr9QacM34jUoPVMgo
  • Unzip the files from there and place at /sdcard/emacs/ on your device.
  • Then, open up ZShaolin and start a session, and type “emacs”. VoilĂ .
Now for getting org-mode to work. Org-mode is part of the basic Emacs setup in recent versions of Emacs (including the one above). For some reason, though, at least when I ran it, I had trouble turning on org-mode. Here’s the fix:
  • Create a .emacs file (if you don’t have one already) in ~ under ZShaolin and put the following into:
(defun load-history-filename-element (file-regexp)
  "Get the first elt of `load-history' whose car matches FILE-REGEXP.
        Return nil if there isn't one."
  (let* ((loads load-history)
         (load-elt (and loads (car loads))))
    (save-match-data
      (while (and loads
                  (or (null (car load-elt))
                      (not (and (stringp (car load-elt)) ; new condition
                                (string-match file-regexp (car load-elt))))))
        (setq loads (cdr loads)
              load-elt (and loads (car loads)))))
    load-elt))
That gets org-mode to work as expected.
fh9YvOc.png
Figure 1: Emacing an org file on Android (with ZShaolin)

Now, most likely you will have org-files that you want to keep synchronized. You may already be running MobileOrg, with something like a Dropbox synchronisation. Note that the way that the MobileOrg app works, you can’t edit the org files that it uses directly. MobileOrg utilises some sort of database and the changes that it pushes back are done so through the database, so editing the org files that MobileOrg is synched with (say, in Dropbox) won’t result in any changes being propagated back to your other devices.

So, if you’re running MobileOrg with Dropbox, you’ll need to have a separate Dropbox synchronisation in order to be able to edit org-files in Emacs on Android in a way that allows for propagation of changes from Android to other devices/repositories.

Here’s a method which allows for editing of org-mode files on Emacs which allows for back-propagation via Dropbox:
  • Create a separate Dropbox synchronisation directory - that is, separate from the one you use for MobileOrg synchronisation. [The way I did this on my Linux desktop was to create a symlink from my “Org folder” in my Documents directory to the “actual” Org directory in my Dropbox folder. In my setup, this directory also synchs with a git repository, so I ended up excluding the hidden .git directory from synching with Dropbox, since I have only a free, very-limited-space Dropbox account.]
  • Open up the Dropbox app on your Android device. Navigate to your new Org directory (not the one you use for MobileOrg). “Open” any of the org files you want to have access to. It doesn’t matter if they successfully open or not - the act of “opening” them gets the Dropbox app to save a local copy which it will keep synchronised with your Dropbox repository.
  • The location for these local files is a path like this: /sdcard/Android/data/com.dropbox.android/files/u87923223/scratch/YourOrgDirectoryName/ the u-number part of the path I assume varies from user to user; and of course the final part of the path will depend on what you named your Org folder and files
  • Files in the above path can be opened in Emacs on Android. Any changes you make will be propagated via Dropbox.
Again, this will be perhaps of limited use on a phone — though ZShaolin does have a built-in software keyboard which works very well for Emacs — on a tablet device with a keyboard (I use an Asus tablet) it works pretty well. (Though I haven’t figured out how to remap CAPSLOCK on my tablet to CTRL yet….)

Saturday, 20 December 2014

In praise of DejaVu (Sans Mono)

I do the majority of my work in Emacs - from the composition of linguistics articles and chapters, to lecture slides, to keeping track of grades, to email. Much of what I do requires a monospaced font, and much of what I do requires a good Unicode font. Which narrows the range of potential font candidates significantly. And, since I spend so much time looking at it, I would like the font to be aesthetically-pleasing.
After trying many different fonts, at different sizes and so forth, I’ve found that DejaVu Sans Mono is really the only font which meets all of these criteria. It is really a good-looking font too. Here it is in a few different applications:

Figure 1: DejaVu Sans Mono in mu4e mail
cMMuHWf.png
Figure 2: DejaVu Sans Mono in LaTeX doc
ox7g0FF.jpg
Figure 3: DejaVu Sans Mono displaying some Unicode
And…it appears to be the same font used in the terminal in Tron: Legacy:
TRON_EMACS.JPG
Figure 4: kill -9ing in Tron: Legacy with DejaVu

Saturday, 23 June 2012

Who uses Linux? (+Emacs, +TeX)

Some really rough notes. Suggestions welcome.

Notable people who use Linux (with additional notes on Emacs and TeX users), a first draft.

My rough criterion for determining who counts as "famous": does the person have a Wikipedia entry? 

Presumably many more can be added under "computer-related" (which is why I put it at the bottom). I'm only listing each person once, under most relevant/salient category (otherwise I could, for instance, list Shuttleworth also under an "astronaut" category).

See also: "The Setup / Linux" and "My Linux Rig" for more 'prominent' people and their Linux setups.

Political

Rick Falkvinge, founder of Swedish Pirate Party [Wikipedia entry]

  • Uses an Ubuntu Linux set-up [1]

Christian Engström, Swedish Pirate Party MEP [Wikipedia entry]

  • Seems to use some sort of Ubuntu Linux set-up [1, 2, 3]
  • Couple of pics with Richard Stallman from 2004 [1, 2]

Amelia Andersdotter, Swedish Pirate Party MEP [Wikipedia entry]

  • Mentions using Arch, Fedora [1, 2]
  • Also Emacs and TeX (see above links)
Vinay Gupta, geopolitical risk analyst [Wikipedia entry]
  • uses Ubuntu Linux [1] 
  • inventor of Hexayurt [1]

Writers

Cory Doctorow, blogger, journalist, & sci-fi/fantasy author [Wikipedia entry]

Charlie Stross, sci-fi/horror/fantasy author [Wikipedia entry]

  • formerly the monthly Linux columnist for Computer Shopper
  • uses Linux, but mainly for running server, otherwise Mac [1, 2, 3]
  • position on piracy: "If you've downloaded unauthorized copies of my books, instead of hitting on a tipjar button, I urge you to buy a (new) copy of one of my books....Your typical book publisher is not like the music or movie industry; they run on thin margins, and they're staffed by underpaid, overworked folk who do it because they love books, not because they're trying to make themselves rich on the back of a thousand ruthlessly exploited artists. I think their effort deserves to be rewarded appropriately..." [1]

Piers Anthony, fantasy/sci-fi author [Wikipedia entry]

  • switched to Linux in 2000 [1, 2, 3, 4]
  • mentions using a number of different distros, including Ubuntu & Fedora [1]
  • use of Linux seems at least in part principle-driven [1, 2]
  • uses LibreOffice [1]
  • concerns about piracy:
    • speaks approvingly of Harlan Ellison's war on piracy (2002-4) [1, 2]
    • complaints about piracy & Ebay (2010) [1]
    • some recognition of danger of censoring internet: "THE WEEK had an item on Internet piracy of music, books, and movies, and efforts to stop it. I have discussed this here before, but it bears repeating: pirates are thieves who are destroying the ability of creative artists to make a living, myself included; a LOT of my works are chronically stolen. The pirates need to be stopped. The problem is how to do it without censoring free expression itself. I think there does have to be a law, but one carefully crafted to shut down only the pirates." (2012) [1]

Neal Stephenson, sci-fi/speculative fiction author [Wikipedia entry]

Actors & film-related

Stephen Fry, actor [Wikipedia entry]

  • big fan of Apple products [1, 2, etc.]
  • but also touts GNU [1, 2, 3]

Wil Wheaton, actor [Wikipedia entry]

  • primarily uses Macs, but also uses Linux [1, 2]
  • support for Bittorrent [1]
Asia Carrera, adult-film actress [Wikipedia entry] 
  • early Linux-adopter, ran own website since 1998 [1, 2]
Cindy Margolis, model [Wikipedia entry]
  • apparent Debian user [1, 2]

Programmers & computer-related

Linus Torvalds [Wikipedia entry]

Richard Stallman [Wikipedia entry]

Mark Shuttleworth, programmer, entreprenuer, astronaut [Wikipedia entry]

Donald Knuth, computer scientist & professor [Wikipedia entry]

  • creator of TeX typesetting system (1978), upon which LaTeX, LuaTeX etc. are based
  • uses Ubuntu Linux (as of 2008) [1]
  • uses Emacs to edit TeX [1]
  • friends with computer security researcher Jacob Appelbaum [1]

American McGee, game designer [Wikipedia entry

  •  switched to Ubuntu Linux (from Windows) with plans to "stay switched" (2006) [1]

John "maddog" Hall, director of Linux International & professor of computer science [Wikipedia entry]

  • runs different Linux distributions depending on employer [1]

Some Initial Ruminations

A number of the people above fall into two rough groupings: "technology/gadget-lovers" vs. "ideological-users". So Stephen Fry and Wil Wheaton would fall into the first category, as would perhaps Charlie Stross and even Linus Torvalds. On the ideological side are (of course) Richard Stallman, Cory Doctorow, Piers Anthony, and the Pirate Party MPs. Anthony's position in the latter grouping is interesting, given his position on piracy. Stallman's position is similar to the Pirate MPs in certain respects, but values the legal status of copyleft.

What about Free Culture proponents?

What computer setups do Free Culture proponents use? Particularly, I'm wondering about Lawrence Lessig, founding father of the Free Culture movement (largely based on Stallman's Free Software Foundation) and founder of the Creative Commons licences. Nina Paley is another prominent Free Culture activist, but I'm pretty sure she's largely (solely?) a Mac user.

Hattrick winners and other random notes

Amelia Andersdotter, Donald Knuth, and Richard Stallman take hattrick prizes for Linux-Emacs-TeX use. (For an extra bonus, Andersdotter also explicitly mentions use of org-mode in Emacs.) 

Of course there are various connections between some of the characters mentioned above. For instance, Doctorow releases his novels under Lessig's Creative Common licences; Doctorow & Stross are co-writing a novel [1]; etc.

In terms of the general public, the actors are (unsurprisingly) probably the best known: I would guess Stephen Fry is the most famous person listed above.

Again, suggestions/additions welcome.

Tuesday, 19 June 2012

Emacs in the future: after the ice-caps melt

Emacs 24.1 is out. I haven't really tried it properly yet. All of the pre-release Emacs 24 snapshots I tried had severe memory-leak problems (at least with my set-up) and the quick try-out of 24.1 I did do revealed that it seems to be incompatible with twittering-mode. Since Emacs 23.3 is still working nicely for me, perhaps I'll wait a bit before trying 24.1 seriously.

Speaking of the future of Emacs, a great quote from sociologist Kieran Healy on The Setup ("usesthis.com") site:
Emacs ... will be there when the icecaps melt and the cities drown, when humanity destroys itself in fire and zombies, when the roaches finally achieve sentience, take over, and begin using computers themselves - at which point its various Ctrl-Meta key-chords will seem not merely satisfyingly ergonomic for the typical arthropod, but also direct evidence for the universe's Intelligent Design by some six-legged, multi-jointed God.

Tuesday, 7 June 2011

Emacs user at work

Despite being designed by a Vim user, and despite its implied criticism of Emacs, I still enjoyed this image:

















ashawley in the comments below points out the similarity with the 1981 cover of the EMACS Manual:



Saturday, 21 May 2011

rms on apple and brain scans


Some Apple addicts truly worship that company, suggest brain scans.
That must be why they allow it to abuse them so much and don't care.
I know a number of Apple fans, and they do tend to have strongly favourable attitudes towards Apple products. (Apple things generally seem to be superior to Microsoft things, but the Apple company doesn't seem any less evil than Microsoft, and Linux is generally superior to both anyway.)

But I question whether this is a reaction which is actually specific to Apple fans. I imagine my brain scans might show similar reactions to GNU/Linux and Emacs.... (Most Windows/Microsoft users probably wouldn't show similar results, given that it's really just the "default" nowadays.)

Wednesday, 6 April 2011

Emacs in Tron

JT Nimoy discusses the creation of software art for creating visual effects in the film Tron: Legacy. Additionally, he mentions that:
In Tron, the hacker was not supposed to be snooping around on a network; he was supposed to kill a process. So we went with posix kill and also had him pipe ps into grep. I also ended up using emacs eshell to make the terminal more l33t. The team was delighted to see my emacs performance -- splitting the editor into nested panes and running different modes. I was tickled that I got emacs into a block buster movie. I actually do use emacs irl, and although I do not subscribe to alt.religion.emacs, I think that's all incredibly relevant to the world of Tron.




Links:
(1) The original article/post by JT Nimoy
(2) On jwz's blog
(3) On boingboing
(4) On reddit

Saturday, 15 January 2011

LaTeX table manipulation using Emacs/AUCTeX+align.el+rectangular selection

Tables in LaTeX are sometimes somewhat difficult to manage; in particular doing anything with columns---in contrast to most word processors, which allow for the manipulation of columns in certain environments (e.g. tables). However, the text editor Emacs in fact allows for rectangular selections anywhere, which means that using Emacs as an editor for (La)TeX files makes working with tables easier.

The AUCTeX package for Emacs adds a vast number of useful features; however, it does not automatically format tabular environments. Here I  offer some notes on how to deal with LaTeX tables in a Emacs/AUCTeX environment.

So let's say we have a LaTeX document containing a (big) table, like this:



















And let's say we want to switch the third and fourth columns. Easily done in a typical word processor, but not necessarily so for a LaTeX document. Let's look at the LaTex .tex source for this table:













A rectangular selection will work only if we have  our columns aligned in our source .tex file. The align.el package for Emacs is needed here (as of Emacs 22, this functionality is built in).

Place the cursor at the beginning of the tabular environment (in our current example, right below the first \hline command will work), and use the align-current function (press M-x and then type align-current RET):

 





[Make sure there are no blank lines in your tabular environment; "align-current" will stop when it hits a blank line.]

If you're working with a large table, as in this example, you still won't be able to see the entire width of the table, so hold down SHIFT and left-click the mouse and choose "Decrease Buffer Text Size" repeatedly until the entire width of the table is visible on your screen (maximizing the Emacs frame to the maximum width of your desktop will be helpful as well...). You should then  be able to view the table as so:















All of our columns are now aligned. Now we need simply to select a rectangular region. There are (at least) two ways of going about doing so. Firstly, the ability to select rectangular regions is a built-in feature of Emacs (see the relevant section of the Emacs manual). Simply select the columnar area (mark it using C-SPC) and press either C-x r r to copy the rectangular area to the register or C-x r k to cut ("kill") the rectangular area and place it in the register. And then use C-x r y to paste ("yank") the copied/cut rectangle into the position you want it (with the cursor in the position of its upper left-hand corner).

However, if your Emacs has the visible selection turned on (as is the default as of Emacs 23), then it is nicer and easier to be able to see the selected area as a rectangle. One nice option is to use the rectangular selection features of the CUA package (a built-in default as of Emacs 22). One of the main functions of the CUA-mode is to change Emacs' copy, kill/cut, and yank/paste keybindings (M-w, C-w, C-y) to the "common" C-c, C-x, C-v. If you, like me, don't want to change the default Emacs keybindings, then include the following in your .emacs configuration file:

(cua-selection-mode t)
(setq cua-auto-tabify-rectangles nil) 

[If you do want the "common" keybindings, then use (cua-mode t) in place of (cua-selection-mode t).]

With this configuration in place, we can now visibly select rectangular areas, and use the normal copy/kill/yank keybindings to copy, cut, and paste the rectangular selections. In CUA-mode rectangular selections are made using C-RET rather than C-SPC. Here is the rectangular selection in our example:











I then kill ("cut") this rectangular area with C-w. And then position the cursor at the point where I want the upper left-hand corner of this rectangular area to be inserted:











And then yank ("paste") the column in its new position with C-y:










That's it. Here is the resulting table (with columns 3 and 4 switched):





















Oh, and here is a nice video demonstration of the use of rectangular selection cut-and-pasting (with CUA-mode): Emacs Column Editing by Mark Mansour. It doesn't deal with LaTeX, but rather HTML; however, it illustrates the general use.

Wednesday, 12 January 2011

Conkeror - browsing the web, emacs-style

As noted below, I've switched from Icecat/Firefox+Pentadactyl/Vimperator to Conkeror. Trying to retool the essentially vi-ish shortcuts to emacs-like shortcuts is rather difficult, and in the end I wasn't able to change some of the shortcuts I wanted to change.  Anyway, Conkeror is simply more interesting: more of a from-the-ground-up approach than an add-on approach.

This post isn't intending as a general intro to Conkeror; if that's what you're looking for, see here or here, or, if you're running Conkeror, press C-h t (that's Ctrl and h at the same time, release, then t) for a tutorial.

Rather like Emacs, Conkeror gets much better than more one personalises/configures it. Some good places to start are on the Conkeror site itself, on Tips from Users page and also the emacs-fu article "conkeror web browsing the emacs way".

In the same spirit, I offer a number of useful customisations I've adopted, some from the two above-mentioned sources, some from other places (including from suggestions on the Conkeror mailling list), and some of my own.

Some initial things:
//allow for 'contrib' stuff
load_paths.unshift("chrome://conkeror-contrib/content/");

// Mode-line
mode_line_mode(true);

// auto completion in the minibuffer
minibuffer_auto_complete_default = true;
url_completion_use_history = true; // should work since bf05c87405
url_completion_use_bookmarks = true;

// display the url before going to it in hints mode
hints_display_url_panel = true;

These are settings taken from here and there. Turning on the mode-line, allowing the url completion (very handy) to access history and bookmarks, and displaying the url of a link (in hints mode).

Customising the mode-line:
// FAVICONS
 require("favicon.js");
add_hook("mode_line_hook", mode_line_adder(buffer_icon_widget), true);
read_buffer_show_icons = true;

// we'd like to see the # of buffers being loaded 
add_hook("mode_line_hook", mode_line_adder(loading_count_widget), true);

// but really we'd also like to know how many buffers are present and which is the current
add_hook("mode_line_hook", mode_line_adder(buffer_count_widget), true);

// remove the clock
remove_hook("mode_line_hook", mode_line_adder(clock_widget));

The first allows for favicons in both mode-line and the C-x b buffer list, the second shows how many buffers are currently still loading, the third shows how many buffers are present and which buffer is the current buffer, the last simply disables the clock. The order of the first three is actually important; this order puts the buffer count on the far left, then the "loading buffer" count, then the favicon, (and then the url of the current buffer).

Tabs & Mouse:
// Tabs
require("new-tabs.js");

//Open Middle-Clicked Links in New Buffers
require("clicks-in-new-buffer.js");
clicks_in_new_buffer_target = OPEN_NEW_BUFFER_BACKGROUND; // Now buffers open in background.

//Bind Number Keys to Switch to Buffers 1-10
function define_switch_buffer_key (key, buf_num) {
    define_key(default_global_keymap, key,
               function (I) {
                   switch_to_buffer(I.window,
                                    I.window.buffers.get_buffer(buf_num));
               });
}
for (let i = 0; i < 10; ++i) {
    define_switch_buffer_key(String((i+1)%10), i);
}
I like having tabs, and the first bit above turns on the tabs, with numbering (but no favicons). I still find it useful to use the mouse from time to time. What's annoying is having to switch from keyboard to mouse or vice-versa. So if I'm using the mouse, I want it to be effective. The second bit above opens new buffers/tabs on middle-clicked links (in background buffers). The last bit allow for quick switching between tabs (the first 10 anyway) using 1-10 (where 0=10). Other useful things to know (though not dependent on this particular configuration): tabs can be closed directly with right click; you can scroll through your tabs by positioning the mouse pointer on the tab bar and using the mouse wheel.

External editor
//set emacs as external editor
editor_shell_command = "emacsclient -c";

// view source in your editor.
view_source_use_external_editor = true;

Set emacs as an external editor (assuming you're running emacs as a daemon), etc.

Managing/Navigating Tab-Buffers
// redefine C-f as "forwards" and C-b as "backwards"
// using F and B (that is Shift+F, Shift+B is actually rather inconvenient since 
// many other command use Control and so requires shifting fingers)
define_key(content_buffer_normal_keymap, "C-f", "forward");
define_key(content_buffer_normal_keymap, "C-b", "back");

// make M-f and M-b switch to next and previous buffers
define_key(content_buffer_normal_keymap, "M-f", "buffer-next");
define_key(content_buffer_normal_keymap, "M-b", "buffer-previous");

// redefine l as "follow link" (like f)
// (too many of the keys are for the left hand, I like "l" for "link")
define_key(content_buffer_normal_keymap, "l", "follow");

// Use M-l to follow link in new background buffer
define_key(default_global_keymap, "M-l", "follow-new-buffer-background");

// open url in new background buffer  (I can't think of a good keybinding for this)
interactive("find-url-new-background-buffer",
    "Open a URL in a new background buffer",
    alternates(follow_new_buffer_background, follow_new_window),
    $browser_object = browser_object_url,
    $prompt = "Find url");

The default keys for navigate forwards and navigate backwards are F and B, respectively. I imagine there are historic reasons behind this (it's how W3 does it), but I find it annoying to have to switch from Ctrl to Shift (since most of the other keybindings involve Ctrl), so the initial bit above binds C-f and C-b to forwards and backwards (F and B still work too). And I bound M-f and M-b to "move to next tab-buffer", "move to previous tab-buffer", respectively. These seem to me to make sense as extensions of the normal behaviour of C-f, C-b, M-f, M-b, in Emacs. [Note: These bindings don't affect the how these keys behave in text boxes. All of these keys retain their expected Emacs-ish behaviour in text boxes.]

I prefer using l for following links in hint mode, so that's another binding added above (f still works too). And I added M-l as "follow link in new background buffer" (works like middle-click).

The last bit is a new command for opening URLs in new background buffers, but I haven't thought of a good keybinding for it so far.

Yanking
// use M-y to google current selection in new buffer
// use M-Y to google current selection in new buffer "double-quoted"

// [ref: http://www.mozdev.org/pipermail/conkeror/2009-February/001334.html ]
// (See also "**c" for selecting text)
interactive("search-clipboard-contents", "Search in Google the content of the X clipboard (the selected text)",
              "find-url",
              $browser_object=
              function(I) {
                  return "g "+ read_from_x_primary_selection();
              }
);
interactive("search-clipboard-contents-doublequoted", "Search in Google the content of the X clipboard (the selected text) as a fixed string",
              "find-url",
              $browser_object=
              function(I) {
                  return "g \""+ read_from_x_primary_selection()+"\"";
              }

);
define_key(content_buffer_normal_keymap, "M-y", "search-clipboard-contents");
define_key(content_buffer_normal_keymap, "M-Y", "search-clipboard-contents-doublequoted");

By default, (outside of text boxes, where, again, Conkeror has the expected Emacs-ish behaviour), M-w copies the selected area. And C-y opens whatever's in the clipboard (I would say kill-ring, but it's not) in the current buffer---assuming that what's in the clipboard is a URL. The above code adds two new commands, performing a Google search on the current clipboard contents, and performing a Google search on the current clipboard contents double-quoted. I bound these to M-y, and M-Y, respectively.

Oh, in general, adding a C-u prefix results in the command being executed in a new buffer. So C-u M-y performs a Google search on the clipboard contents in a new (focussed) buffer.

More buffer management/misc. bindings
// make C-c C-c "submit form"
define_key(content_buffer_normal_keymap, "C-c C-c", "submit-form");

// make C-x 0 "kill current buffer"
define_key(default_global_keymap, "C-x 0", "kill-current-buffer");

// make C-x 1 "kill other buffers"
define_key(content_buffer_normal_keymap, "C-x 1", "kill-other-buffers");

// make C-x 2 "duplicate buffer"
interactive("duplicate-buffer", "Duplicate buffer",
            function (I) {
              browser_object_follow(I.buffer, OPEN_NEW_BUFFER, I.buffer.current_uri.spec);
            });
define_key(content_buffer_normal_keymap, "C-x 2", "duplicate-buffer");

Use C-c C-c to submit forms.

Now Conkeror doesn't have "windows" in the Emacs-sense. It has buffers/tabs. So the above commands depart somewhat from being truly parallel with Emacs behaviour, since in Emacs these commands all involve window management. But I still find it useful to have some keybinding for these commands, and these make a sort of sense to me. C-x 0 closes the current tab-buffer (C-x k is the command for "close buffer" in general; it defaults to the current buffer, but requires another keystroke (Enter)); C-x 1 closes all tab-buffers except for the current one; C-x 2 duplicates the current tab-buffer in a new tab.

Set default download directory
// cwd
cwd=get_home_directory(); 
cwd.append("Downloads"); 

This sets the default download directory to "~/Downloads". "cwd" is useful, and can be used cross-platform. It gets the "home directory". The last line obviously appends "Downloads" to the home directory location.


Misc.
// xkcd add mouse-over text
xkcd_add_title = true;

// No new window for downloads
download_buffer_automatic_open_target=OPEN_NEW_BUFFER_BACKGROUND;

// Make sure I don't close by accident
 add_hook("before_quit_hook",
           function () {
               var w = get_recent_conkeror_window();
               var result = (w == null) ||
                   "y" == (yield w.minibuffer.read_single_character_option(
                       $prompt = "Quit Conkeror? (y/n)",
                       $options = ["y", "n"]));
               yield co_return(result);
           });

can_kill_last_buffer = false;

Show xkcd mouse-over text on the page below the cartoon (it would be nice to have another way of handling mouse-over text though).

The second command handles how the download info buffer is handled; here it opens in a new tab rather than opening a new window ("frame" in the Emacs sense).

The last bits makes sure that if by accident I hit C-x C-c rather than C-x C-v it doesn't close everything without asking me, and then final line disallows killing of the last buffer.

Webjumps
Webjumps are a useful feature of Conkeror. In the mini-buffer, instead of typing a url, one can type a webjump. A number of such webjumps are built-in to Conkeror already. For example, "google emacs" will open a google search for "emacs". Actually, "g emacs" will do the same thing, and that's preferable since it's relatively quick to type. Also, "wikipedia emacs" will open the wikipedia page on "emacs", etc. Conkeror also already has webjumps designed for use with del.icio.us (press C-h i for more info).

And you can define your own webjumps. Here's a good page of some other useful webjumps you can add. Webjumps are not limited simply to site names, but can include javascript code as well. Here are a couple relatively simple ones I wrote for adding favourites to Stumbleupon and adding stories to Digg:


// Define add favourite to Stumbleupon
 define_webjump("astumble","javascript:location.href='http://www.stumbleupon.com/submit?url='+encodeURIComponent(location.href)+'&title='+"+"encodeURIComponent(document.title);");

// Define Digg story
define_webjump("adigg","javascript:location.href='http://www.digg.com/submit?url='+encodeURIComponent(location.href);");


And here's a screenshot:


Wednesday, 22 December 2010

Hack - Emacs calendar: Indian/Nepali/Hindu holidays for 2011

Ideally, it would be nice to calculate these automatically for all years (and to be able to convert from Gregorian to Vikram (Bikram) Samvat dates).... But for now, this can be inserted into your .emacs file to display Hindu holidays for 2011:

;; Hindu Holidays (North India/Nepal)
(setq holiday-other-holidays 
'(
(holiday-fixed 1 14  "Makar Sankranti")
(holiday-fixed 2 8   "Vasant Panchami / Saraswati Puja")
(holiday-fixed 3 3   "Maha Shivaratri")
(holiday-fixed 3 19  "Holi")
(holiday-fixed 4 4   "Bikrami Samvat / Hindu New Year [2068]")
(holiday-fixed 4 12  "Ram Navmi")
(holiday-fixed 4 18  "Hanuman Jayanti")
(holiday-fixed 5 6   "Akshaya Tritiya (Akha Teej)")
(holiday-fixed 6 15  "Savitri Puja")
(holiday-fixed 7 15  "Guru Purnima")
(holiday-fixed 8 4   "Naag Panchami")
(holiday-fixed 8 12  "Mahalakshmi Vrata")
(holiday-fixed 8 13  "Raksha-Bandhan + Janai Purnima")
(holiday-fixed 8 22  "Krishna Janmashtami")
(holiday-fixed 9 1   "Ganesh Chaturthi")
(holiday-fixed 9 9   "Indra Jatra begins")
(holiday-fixed 9 11  "Kumari Indra Jatra")
(holiday-fixed 9 17  "Indra Jatra ends")
(holiday-fixed 9 11  "Teej")
(holiday-fixed 9 13  "Pitr-Paksha begins")
(holiday-fixed 9 27  "Mahalaya (Pitr-Paksha ends)")
(holiday-fixed 9 28  "Navaratri begins")
(holiday-fixed 10 3  "Durga Puja begins (Maha Saptami)")
(holiday-fixed 10 5  "Navaratri ends")
(holiday-fixed 10 6  "Dasain/Dusshera (Vijaya Dashami)")
(holiday-fixed 10 11 "Lakshmi Puja (Sharad Purnima)")
(holiday-fixed 10 16 "Karwa Chauth")
(holiday-fixed 10 25 "Dhan Teras")
(holiday-fixed 10 26 "Diwali / Deepavali / Tihar")
(holiday-fixed 10 28 "Bhai Dooj")
)
)

You may want to add other holidays as appropriate, e.g. South Indian holidays; holidays specific to the Punjab, Orissa etc. The format is:
(holiday-fixed numeric-value-of-Gregorian-month numeric-day-of-month "Name-of-Holiday").

E.g. (holiday-fixed 3 5 "Losar") for the holiday Losar falling on 5th March.

Wednesday, 17 November 2010

Hack: Emacs-like bindings for Pentadactyl

Pentadactyl -- the successor of Vimperator -- can speed up your web-use, especially if you're used to using a high-powered editor like Vi(m) or Emacs.

I've started using Emacs a lot recently, because of the brilliant Emacs TeX packages  (i.e. AUCTeX and RefTeX, preview-latex, outline mode), thus I've got used to Emacs-like bindings.

So, inspired by anrxc's vimperator bindings (but differing significantly from them in many places): a configuration file for  that provides an Emacs-like set of keybindings for Pentadactyl.

1) .pentadactyl configuration file
2) QuickReference 'card' as PDF
3) QuickReference 'card' as TeX
4) QuickReference 'card' as HTML 


This is version 1. Comments/suggestions welcome.

[Edit (2011-Jan-11): With the latest version of Pentadactyl, something seems broken (the mode-line isn't appearing). I don't know if this is something with the configuration or some deeper change to Pentadactyl. However, I've switched to Conkeror, so I'm no longer actively updating this config.

See this BabbageFiles post, "Browsing the web, Emacs-style - with Conkeror".]
]