emacs,common-lisp,slime , Hide `(declare)` forms in lisp mode


Hide `(declare)` forms in lisp mode

Question:

Tag: emacs,common-lisp,slime

This is actually two questions:

  1. Does anybody know an emacs feature that can hide (and maybe indicates that it has done so) selected forms in lisp code ? I've written some performance oriented common lisp and the key functions do contain lots of (declare (type ...)) forms that clutter the code.

  2. If not, does anybody have suggestions on where to be inspired / steal something that would enable me to write it myself ?

Cheers and thanks!


Answer:

Write a function that finds the start and end positions of the text you want to make invisible. Then use (put-text-property START END 'invisible t) to make the text invisible.

For a quick-and-dirty example, use (search-forward "(declare (type " nil t). (match-beginning 0) is the start position of that sexp, so (goto-char (match-beginning 0)), then do (forward-sexp 1) to get to its end position. Then use put-text-property as above, to hide the text from the start of the declare sexp until its end. Do that in a loop, to hide all such sexps.

To be more careful, you would use a regexp that allows variable whitespace (including newlines) in the sexp, etc. But just the above should get you started.

(To make invisible text visible again, just use (put-text-property START END 'invisible nil).)


Related:


Emacs code hints in minibuffer. How do I get them?


emacs,code-hinting
I've looked all over the internet for this, and since I'm new to Emacs, I don't know what to search for. I'm not looking for mini-buffer completion for commands and such. I'm looking for code hints in the mini-buffer, as shown in this gif. I couldn't care less about the...

How to define a function with a variable number of arguments?


emacs,elisp
Instead of this: ((lambda (a b) (apply '+ (list a b))) 1 2) it is possible to write this in Scheme: ((lambda args (apply '+ args)) 1 2) Now it is possible to pass more than two arguments to the function. When I try it in Emacs Lisp I get...

Configuring Flycheck to work with C++11


c++,c++11,emacs,flycheck
I am having significant trouble configuring flycheck for C++11. Right now, flycheck is flagging things like std::to_string(). The checker I am using is just g++. What can I add in the .emacs file such that flycheck will assume C++11 by default?

Insertion into a list doesn't reflect outside function whereas deletion does?


list,lisp,common-lisp
I am new to Lisp. Deletion of an item in a list by a function gets reflected outside the function but insertion doesn't. How can I do the same for insertion? For example (defun test (a b) (delete 1 a) (delete 5 b) (append '(5) b) (member '5 b)) (setq...

If strings are vectors, why are they immutable?


lisp,common-lisp
if strings are vectors of characters, and a vector's elements can be accessed using elt, and elt is setf-able - then why are strings immutable?

Updating the window in response to CLIM frame commands


common-lisp,clim,mcclim
While trying to figure out CLIM, I ran into this example program. It's a simple maze game. The author claims to have tested it in LispWorks (and even has #+Genera in there, implying that this program would work on a real Lisp Machine), but I'm trying to get it working...

custom-set-variables add blank space on subsequent uses


emacs,elisp
I followed the emacs haskell tutorial, and couldn't understand some of its language regarding the use of custom-set-variables in the text quoted below. It seems that custom-set-variables should be used in one way on first usage, and another way (with added blank space) on subsequent uses. My questions are: What...

Common Lisp Object System method execution order


lisp,common-lisp,clos
I have the following two classes: (defclass person () ()) (defmethod speak ((s person) string) (format t "-A" string)) (defmethod speak :before ((s person) string) (print "Hello! ")) (defmethod speak :after ((s person) string) (print "Have a nice day!")) (defclass speaker (person) ()) (defmethod speak ((i speaker) string) (print "Bonjour!"))...

where is the text printed by C printf


io,common-lisp,cffi
I happened encounter a trouble with calling C printf function from SBCL via cffi. The problem is when I call printf function, I can't find the output text, just the return value of printf function show on the REPL. But when I quit SBCL, the output text appears on the...

Is there any mode for Rails' *.js.erb in emacs or I must use TextMate?


javascript,ruby-on-rails,emacs
I googled for "emacs js.erb" and got nothing valuable, Now I use web-mode for it, but obviously web-mode is not for *.js.erb: it can not auto complete the html tag, such as </div>. For <% ... %>, <%= .. %> and so on, it can not indent them. For javascript...

Emacs dired, what controls the color of the title line of a directory


emacs,dired
As the picture shown in attachment, what is the variable, if any, that controls the color of the title line of the directory? I'm trying to change the darkgreen to grey.

Emacs hotkey for diffing buffer from file without reading (confirming) buffer name


emacs,elisp
I have made a hotkey that calls the diff-buffer-with-file command but then you have to hit enter to confirm that the file you are on is the one to correctly diff: (global-set-key (kbd "C-c e") 'diff-buffer-with-file). I looked up the documentation and saw that you also give &optional BUFFER, so...

looking for help in configuring .emacs file for python (python.el),


emacs,python.el
My emacs version is 24.5, using in built python. I have written these lines in my .emacs for it: (require 'python) (setq python-shell-interpreter "C:/Python34") The problem is none of the commands (when I am trying to run test.py) are working. I have tried several commands named like M-x python-shell-* and...

How to start Emacs For Mac OS X from the command line without blocking?


osx,emacs
A tip from the website of Emacs For Mac OS X suggests executing the following script to start it from the command line: #!/bin/sh /Applications/Emacs.app/Contents/MacOS/Emacs "$@" However, this will block the command line until Emacs.app exists. Is there a way to start it from the command line without blocking?...

How do EMACS Lisp programmers read text files for non-editing purposes?


file-io,emacs,elisp
What do EMACS Lisp programmers do, when they want to write something roughly the equivalent of... for line in open("foo.txt", "r", encoding="utf-8").readlines(): ...(split on ws and call a fn, or whatever)... ..? When I look in the EMACS lisp help, I see functions about opening files into text editing buffers...

Emacs bindings documentation


emacs,elisp
I am writing some bindings to lambdas in my ~/.emacs and would like to have a description of what the function does appear when I do (for example) C-c ?. I tried to put a string immediately after lambda () but that still does nothing. How do I get something...

Read input into string in Lisp reader macro


macros,common-lisp,reader-macro
I am trying to make a reader macro that would convert @this into "this". This is what I currently have: (defun string-reader (stream char) (declare (ignore char)) (format nil "\"~a\"" (read-line stream t nil t)) ) (set-macro-character #\@ #'string-reader ) The problem is that this requires that I put a...

Running compiled lisp program with clisp-2.49 on OS X


common-lisp,clisp
I have just started out programming in Common Lisp using GNU clisp-2.49 (compiled from source) as my implementation on OS X 10.10 Yosemite. I've written a simple "Hello World" program as follows: (EXT:SAVEINITMEM "test" :INIT-FUNCTION 'main :EXECUTABLE t) (defun main () (format t "Hello World!") (EXT:EXIT)) When I run: $...

MELPA pointing to non-existent version of multi-term?


emacs,package,melpa,multi-term
I am trying to use MELPA to install the emacs package "multi-term". When I do package-install multi-term, I get "http://melpa.org/packages/multi-term-20141203.1658.el: Not found". However, a more recent version http://melpa.org/packages/multi-term-20150220.1320.el is on MELPA. Why is emacs not installing this version?

How to move a file in Lisp using rename-file


lisp,common-lisp,pathname
What's the best way to move a file in Lisp in an implementation-independent way? For example I have an image file: (setq oldpath #P"SERVER:PICTURES;TEMP;PHOTO.PNG") and I want to move it out of the TEMP directory into the PICTURES directory. This seems to work: (setq newpath (make-pathname :host (pathname-host oldpath) :directory...

Task Dependency in org-mode


emacs,org-mode
I am trying to setup org-capture or org file for following issue: Task A is the major task. It depend upon minor tasks B and Task C. Now in org-agenda view, I should be able to see Task B and Task C. When they are done, I should be able...

Backquote String Interpolation


macros,lisp,common-lisp
Is it possible to use lisp's macro to do string interpolation? For instance, can I make a macro like this: (defmacro test (a) `",a") So that (test abc) returns "abc" as a string? I could probably cheat by quoting it and turning that quote into a string, but that doesn't...

How to get Emacs to sort lines by length?


sorting,emacs,elisp
I'd like to be able to highlight a region in Emacs and then sort the region by line length. The closest I've found is the following code which I think will sort by length: (sort-subr t #'forward-line #'end-of-line nil nil (lambda (l1 l2) (apply #'< (mapcar (lambda (range) (- (cdr...

Elisp: how to make this function short


emacs,macros,elisp
I am implementing an plugin, which a lot of project types are remembered. For example: angular, meteor, ember, rails ... And keyed arguments are used. The function creates an hash table with provided keys and values, and assign the hash table to another hash table. Code below: (defun jst-remember-project-type (type...

sbcl run-program hang when there is large amount of output from program


common-lisp,hang,sbcl
Recently I find a run-program hang issue of sbcl 1.2.7 (32bits, linux). The code as following (progn (with-open-file (s "test.out" :direction :output :if-exists :supersede) (loop repeat 900 do (write-line (make-string 76 :initial-element #\x) s))) (run-program "/bin/bash" (list "-c" "cat test.out") :output :stream)) That is when the "cat test.out" produce many...

Invalid specialized parameter in method lambda list


lisp,common-lisp
I am trying to write a simple coin flip program in Common Lisp. This is the code I have (defun yn (let ht (random 1) (if (eq ht 1) (princ heads) (princ tails)) ) ) It seems simple enough, but I keep getting the error: "Invalid specialized parameter in method...

Confused when setting an Emacs face


emacs,elisp
(set-face-attribute 'diredp-dir-heading nil '(t (:foreground blue :background dark1))) What should be the right statements to set this face? Bow//...

Exceed evaluation depth when forward function in Emacs Lisp


emacs,lisp,elisp
Here is just a simplified code snipped I have not managed to work. I do not understand what is wrong. (defun enumerate-indicies (func) (let ((index 0)) (while (< index 5) (funcall func index) (setq index (1+ index))))) (defun enumerate-multiplied-indicies (func) (enumerate-indicies #'(lambda (index) (funcall func (* 10 index))))) The following...

emacs: Symbol's function definition is void: loop


emacs,elisp,emacs-prelude
I am testing on loading packages in emacs init.el (Emacs 24.3). I followed a blog by the author of emacs prelude to automatically load packages, and copied the code there into my init.el as in the bottom. However, I got an error message about the loop function/symbol, which says: Symbol's...

Result value of elisp code stored in a file?


emacs,elisp,emacs24,dot-emacs
Looking for a way how evaluate elisp code stored in an external file and pass its result as a function argument. Example demonstrating what I'd like to achieve follows: ;; content of my_template.el '(this is a list) ;; content of .emacs where result of my_template.el has to be used (define-auto-insert...

Dynamic 2d array in lisp


common-lisp,clisp
I want to have a 2D array in Lisp . But each row can have different number of elements(At max 5). So I thought of maintaining another single list to store the current sizes of each row, and update them whenever required. So, my code goes like this : (setq...

lisp: dynamic scope vs explicit parameter passing


design-patterns,coding-style,common-lisp,anti-patterns,dynamic-scope
I see two different patterns for "output" functions in (common) lisp: (defun implicit () (format t "Life? Don't talk to me about life!")) (defun explicit (stream) (format stream "This will all end in tears.")) (defun test-im-vs-ex-plicit () (values (with-output-to-string (stream) (let ((*standard-output* stream)) (implicit))) (with-output-to-string (stream) (explicit stream)))) Is using...

Emacs - selection not showing in windowed mode


emacs
I have Emacs on a Kubuntu 15.04 OS and I have a problem in showing the selected region; if I run emacs in the terminal windows with -nw option, I can set marks and I see the selected region highlighted; but if emacs starts in a window, the selected region...

What is a common-lisp analogue of python's argparse?


python,common-lisp,argparse
What is a common-lisp analogue of python's argparse library for parsing command-line arguments?

org-mode built-in table editor on windows


windows,emacs,org-mode
I am using org-mode version 8.2.2 and Emacs 24.2.1 on Windows 7 and have been struggling with the alignment of org-mode tables. Creating a simple table in org-mode using the build in editor gives me an unaligned table unaligned table columns | first col | second col | third col...

Getting `which-func-mode` output as a string in Emacs lisp


emacs
I am trying to retrieve the output which-function-mode as a string in Emacs. I am going to create a keyboard binding shortcut that copies it to my clipboard. It seems like this (which-func-mode ("" which-func-format " ")) is used to insert which-function into Emacs header line. However, I can't seem...

Creating A Process Queue in Common Lisp


common-lisp
I have a server running Hunchentoot (CentOS and SBCL). When a user submits a specific type of post request, a subprocess is launched (run-program) which can take up to four minutes to complete. If five people perform that specific type of request at the same time, the server runs out...

Local dynamic binding in common lisp


closures,common-lisp,dynamic-binding
Honnestly, I'm not sure I fully understand what it means for a binding to be "dynamic" versus "lexical". But I understand that when I use defvar or defparameterto define a binding, 1. it declares a global variable 2. the binding is declared "special", so that it can be shadowed by...

What does the non-terminating-p argument of set-macro-character do?


macros,common-lisp
Set-macro-character has an optional argument called non-terminating-p. It seems to be used to indicate whether another character should be read after reading the macro character, but the reader algorithm seems to ignore this argument. Is there a difference whether I set it to true or false?

Error in Dired sorting on Windows (with Cygwin Emacs)


windows,emacs,cygwin,dired
In a Cygwin Emacs on Windows, in Dired, if I try to sort by time (for example), I get the error: insert-directory: Listing directory failed but `access-file' worked In a Windows Emacs binary on Windows, I do not have any problem, but Emacs uses its own implementation of ls IIUC....

How to omit certain folders on ido-switch-buffers and ido-dired?


emacs,dired,ido
I would like to ignore certain folders turning up via ido-dired when changing buffers in Emacs. These folders are system folders on a Mac and should not be removed otherwise, so at least I would like to hide them (especially annoying is, for example, ~/Documents which is suggested when one...

Structuring large Lisp applications


lisp,common-lisp,quicklisp,asdf
I am currently trying to wrap my head around packages, systems & co. I now have read Packages, systems, modules, libraries - WTF? a few times, and I think I'm still having difficulties to get it right. If I simply want to split a Lisp source file into two files,...

Trying to multiply all elements in a list of sublists with elements in another list in lisp


list,common-lisp
I'm trying to multiply a list with n sublists with a list with n scalars. It's supposed to work like this: (kmult-matrix '((3 4 2 4) (2 5 6 9) (1 -2 8 10)) '(2 3 5)) => ((6 8 4 8) (6 15 18 27) (5 -10 40 50))...

Shell (zsh) through Emacs?


emacs,zsh
I usually run emacs in a terminal to work. I would like to run a shell inside a emacs window. I've found the shell command, but I would like to run the zsh I usually use inside (with my own configuration). Is it possible? EDIT : I succeeded to run...

EMACS-Live + Slime error at startup


emacs,common-lisp,slime,kubuntu
Ok, I must be missing something obvious. I'm getting stuck since yesterday to launch Emacs-live + slime. I'm using EMACS 24.3.1, installed Emacs-live and it worked well (if I start emacs-live without Slime it works), downloaded Slime-Pack from git and added this line to .emacs-live.el (live-append-packs '(~/.live-packs/slime-pack/)) I'm on a...

EVAL/APPLY: too many arguments given to F


lisp,common-lisp,clisp
Hello why do i get *** - EVAL/APPLY: too many arguments given to F on function call with nested lists parameter. I cannot figure it out, since I passed a simple nested list. (defun f (L) (cond ((NULL l) nil) ((listp (car L)) (append (F(car L))) (F(cdr L) (car (F...

org-mode agenda view matching tag and todo state


emacs,org-mode
I would like to create an agenda view with org-agenda-custom-commands, which will connect capabilities todo-tree and tags-tree. That's what I want to achieve, this sparse tree suited to such a search C-c / m JOB+TODO="NEXT"...

ESS produces “Variable binding depth exceeds max-specpdl-size”


r,emacs,ess
I am trying ESS (Emacs Speaks Statistics). The problem is: Ctrl-P and the up-arrow are disabled on any buffer because of the following error: Variable binding depth exceeds max-specpdl-size The trigger is the following line in .emacs.el (require 'ess-site) This line is needed to load ESS. If I delete this...

word-wrap — using `'cursor t` when overlay 'after-string at end of visual line


emacs,elisp,overlay
PROBLEM:  When point is at the end of a visually wrapped line (but not at the very end of the line), the cursor does not respect the cursor t setting of the overlay after-string -- i.e., the cursor appears at the beginning of the next visually wrapped line, instead of...