NEUROMUSE3

Work in progress …

code source


Table des matières

Tips and tricks

LISP

  • Get symbols from package(s):
(defun get-all-symbols (&optional package)
  (let ((lst ())
        (package (find-package package)))
    (do-all-symbols (s lst)
      (when (fboundp s)
        (if package
            (when (eql (symbol-package s) package)
              (push s lst))
            (push s lst))))
    lst))

Then do:

(get-all-symbols 'NEUROMUSE3) ; returns all the symbols from the NEUROMUSE3 package
  • Get specific symbols:
(apropos-list "id-" 'NEUROMUSE3)

Returns all symbols whose name contains the string you pass in, and takes an optional package to search.

  • To reset hash-table (delete all hash entry, meaning each key and its associated value from the hash-table):
(defun reset-ht (ht)
  (maphash (lambda (k v) (declare (ignore v)) (remhash k ht)) ht))

or simply:

(clrhash ht)
  • To get documentation string:
;; for instance to get the documentation of the lisp function sort (in ccl clozure):
(documentation 'sort 'function)
"Returns SEQUENCE, which has been modified to be in order.
   If sequence is a displaced array, sorts just that portion of the
   data-array which is part of SEQUENCE."

SLIME

  • To reset state LISP with slime: M-x slime-restart-inferior-lisp
  • To select your common lisp implementation: M-- M-x slime ; then enter the name (sbcl or other …) of your lisp implementation.

EMACS

  • To get tilde in emacs, write the following in .emacs file:
(defun tilde () (interactive) (insert "~"))

After that, simply do: M-x tilde

  • M-u → upcase-word
  • Emacs Split Window Commands
Purpose Command Name Key
split top/bottom split-window-below 【Ctrl+x 2】
split left/right split-window-right 【Ctrl+x 3】
unsplit all delete-other-windows 【Ctrl+x 1】
remove current pane delete-window 【Ctrl+x 0】
move cursor to next pane other-window 【Ctrl+x o】

SHELL

  • To kill process from terminal:
kill $(ps aux | grep '[p]rocess-name' | awk '{print $2}')
  • To check pid and port of a named process using socket:
lsof -Pni4 | grep process-name

And to get the last one:

lsof -Pni4 | grep process-name | tail -1
  • Find a word inside a folder and inside all lisp files:
grep -inr <string> *.lisp

BASH

  • To manage lisp packages:
#!/bin/bash
 
usage(){
    echo "Usage: lisp2pack add package-full-pathname"
    echo "   or: lisp2pack add asd-file-full-pathname"
    echo "   or: lisp2pack rem package-name"
}
 
destpath="$HOME/lisp"
 
mkdir -p $destpath/packages
mkdir -p $destpath/systems
 
if [[ ! $@ ]] 
then usage; exit 1
fi
 
if [ $1 = add ]
then
    if [ -d $2 ]
    then
        asdpath=`ls $2/*.asd`
	mv $2 $destpath/packages/
	cd $destpath/systems/
	ln -s $destpath/packages/$(basename $2)/$(basename $asdpath)
	echo "---> package $(basename $2) installed."
    elif [ -f $2 ]
    then
	ext=`echo "$(basename $2)" |awk -F . '{print $NF}'`
	name=`echo "$(basename $2)" |cut -f 1 -d '.'`
	if [ $ext = asd ]
	then
	    cd $destpath/systems/
	    ln -sf $2
	    cd $destpath/packages/
	    ln -sf  $(dirname $2)
	    echo "---> package $name installed."
	fi
    else
	usage; exit 1
    fi
fi
 
if [ $1 = rem ]
then
    rm $destpath/systems/$2.asd
    linkval=`readlink $destpath/packages/$2*; echo $?`
    if [[ $linkval = 1 ]]
    then
	mv $destpath/packages/$2* $HOME/Desktop/
	echo "---> package $2 uninstalled and moved to the desktop."
    else
	rm $destpath/packages/$2*
	echo "---> package $2 uninstalled."
    fi
fi
 
# Write in .ccl-init.lisp (for ccl64) and/or .sbclrc the following lisp code (according that the folder named lisp is in your home directory, if not adjust the path):
#      (require 'asdf)
#      #(pushnew (merge-pathnames (make-pathname :directory '(:relative "lisp" "systems")) (user-homedir-pathname)) asdf:*central-registry* :test #'equal)
#      (push (merge-pathnames (make-pathname :directory '(:relative "lisp" "systems")) (user-homedir-pathname)) asdf:*central-registry*)
# Then run this script (name it lisp2pack or lisp2pack.sh) to install any lisp package.
# To load a package in your lisp implementation type: (require 'package-name).
Imprimer/exporter
QR Code
QR Code wiki:tips_and_tricks (generated for current page)