segunda-feira, 15 de junho de 2015

Package-require: require a library, eventually loading the package from the Emacs package archives

package-require is an Emacs Lisp utility function that will install a package if not installed from the archives, and then load the corresponding library. If the library name differs from the package name, it can be supplied.

(defun package-require (package-name &optional library-name)
  "Install the package named PACKAGE-NAME from the repositories
  if it doesn't exist locally and then load the library given by
  LIBRARY-NAME, or PACKAGE-NAME if it is homonimous.  Both names
  are strings, not symbols."

  (let ((package (intern package-name)))
    (unless (package-installed-p package)
      (package-install package)))
  (load-library (or library-name package-name)))

To use it, write in your emacs file, for instance:

(package-require "bpe")

What if the package name differs from the library to load, like in AucTeX? Just write the library name after the package. The following example loads "tex-site", installing "auctex" first if it does not exist.

(package-require "auctex" "tex-site")

A shell script to redo the home .cabal directory

Haskell user installation: automation with an interface

Note: A new version was posted at the 16 Jun 2015.  Please use the download link below, as it has been updated.

Haskell is a powerful language that you will love to hate and hate yourself to death by loving it. Haskell is expressive and, in my experience, will teach you more and more about computation as you use it. Like python, opens a new way to think of computing architecture and algorithms.
One of the most interesting tools of Haskell is The Haskell Cabal. Cabal is a system for building and packaging Haskell libraries and programs. There is a tool, cabal-install, which retrieves programs and libraries from source repositories, builds them on the local machine, and installs them by default in the user's home directory. It also allows sandboxes, directories whose library setup differs from the user or from the system libraries, used mainly for development.

Shell to the rescue

Since cabal is not a package manager, after a while you will find that it is more fruitful to just wipe the whole user installed packages and start over. It usually meant for me remembering all the packages I use and install them by hand. I have made before a shell script to help me automate that task. It worked very well, but I failed always to remember all the command line arguments I had to pass to install certain sections.
The following script is a bash script that will wipe out the ~/.cabal and ~/.ghc directories (with the exception of the configuration files) and restart the installation. Running this shell script allows an user to fire it and forget until it is built. It is nothing sophisticated, nor it needs to be. It just does the job.

Download

Link for download: haskell.

Requirements

It uses the Bourne Again Shell (bash), and has some code specific to bash. You should have it installed on your machine (all Linux distributions have bash, and most use it by default).
You should also have a working installation of Haskell in your computer, with the Cabal development libraries and the cabal command line tool.

Usage

Just follow the menus. You can wipe the whole cabal installation (.cabal and .ghc). This script always preserve the configuration files.
As for the main menu:

  • Clean wipes the cabal installation.
  • Install wipes the previous installations and installs only cabal.
  • All reinstalls all package blocks, unattended. Fire it up and go on a date. It'll be ready when it is ready.
  • All other items install some package blocks.

What if I want different packages?

Edit any of the functions beginning by install_, adapting them to your needs. If you want a new block, add it to the main menu, and create a corresponding do_ function, taking the existing ones as example.

Licence

Public domain.
If you wish to suggest improvements, feel free to add them to the comment box, and I'll open a git repository in github.