common lisp help equivalent to help in python - emacs

At a python interpreter, one can simply type help("name") to visit documentation for name.
What is the equivalent in a common-lisp REPL (I am using SBCL)?
Note that I am using SLIME in emacs 24.3
Thanks in advance.

Try these:
(documentation #'cons 'function)
(documentation 'most-positive-fixnum 'variable)
(describe #'cons)
Slime also has a bunch of shortcuts for looking at things: slime-describe-symbol, slime-inspect (and if you have the hyperspec sitting around, slime-documentation-lookup) might all be useful.

Related

In emacs dired mode, is there a setting that dired uses eshell-ls and other eshell commands?

This answer https://emacs.stackexchange.com/questions/28981/finding-files-by-names mentions
"If you are running Dired with a 'ls' implemented in elisp, 'ls-lisp' or 'eshell-ls', then you can recursively list all the files matching a wildcard".
But I do not know how to achieve that.
Is there a way (customization or setting in init.el) to ask dired to use eshell commands where available?
You can use ls-lisp emulation (ls-lisp.el), which is part of vanilla Emacs. (Someone else will hopefully answer for eshell.)
To enable ls-lisp, customize option ls-lisp-use-insert-directory-program to the value nil.
See the Emacs manual, node ls in Lisp.
See also Emacs Wiki page ls Lisp.
Drew's answer showed me the path. Looking through eshell variables, it looks like to enable eshell-ls in lisp, we can use eshell-ls-use-in-dired to 't:
(setq eshell-ls-use-in-dired 't)

STYLE-WARNING: in SLIME 2.12 SBCL 1.2.7 Gnu Emacs 25

I get this message when starting SLIME:
; loading #P"d:/lisp/slime-2.12/swank-loader.lisp"
STYLE-WARNING: redefining EMACS-INSPECT (#<SB-PCL:SYSTEM-CLASS T>) in DEFMETHOD
The REPL works normal.
I am totally new to EMACS and SLIME and I'd like to know what does this mean and how to fix it.
I use Windows 8 (64-bit), GNU Emacs 25.0.50.1 (x86_64-w64-mingw32), SLIME 2.12, and SBCL 1.2.7
I addressed folks in GitHub and jackcarrozzo replied
with this post:
Good question - it took a bit of spelunking to find a full answer. The short answer is that emacs-inspect stores handlers for inspecting objects; when a particular object is inspected, the relevant generic function (based on type) will match and be evaluated. From http://lisp-book.org/contents/chslime.pdf page 16, you can run this to see the currently-attached generics:
M-. swank-backend:emacs-inspect
That pdf also describes creating your own inspector as well as additional features that look pretty cool.
Regarding your second point: lots of stuff gets printed to the slime-events buffer; unless you're having a slime-specific issue, you probably don't need to even have it open in a window. Warnings and so forth relevant to your code and interactions will come out either directly in the REPL, in the inferior-lisp buffer, or in one of a few other buffers that emacs/slime will auto-open for you when needed.
CL-USER> (use-package :elk)
; Evaluation aborted on #<SB-KERNEL:SIMPLE-PACKAGE-ERROR "The name ~S does not designate any package." {1002C9D683}>.
CL-USER> (defun moose (a) (+ a 7))
MOOSE
CL-USER> (defun moose (a) (+ a 8))
STYLE-WARNING: redefining COMMON-LISP-USER::MOOSE in DEFUN
MOOSE
CL-USER>
So, in summary: don't worry about it. Slime makes interfacing Common Lisp in emacs simple, and it does a great job of staying out of the way. Slime does admittedly have a ton of features but it doesn't force you to use them. Note to self: I should really get around to learning them some day...

Autocompletion with Emacs and tags

Hi I work on a very large and complex C code base (complex not in a good way). The codebase dwarfs the linux kernel to give you an idea. I have set up emacs to do most of what I want. I get autocompletion on functions and variables but there are certain things which do not work (omni-completion).
I use cedet v2, xgtags, auto-complete, yastnippet, cscope and a few other tools all of which are installed via el-get on emacs-24. When I work on a smaller project, omni-completion in C works so I would get a list of the members of a struct when I access the object. However, in the very large "project", omni-completion does not work when accessing a struct. As I said, I get completion on functions and variables but not on structures.
My explanation is that auto-completion is using its parser which cannot handle the size and complexity of the codebase. However, gtags or etags can handle it.
Is there a way to make auto-complete look into the gtags (xgtags) database? My gtags are working very well indeed.
EDIT:
I am not an admin on my system and I cannot install packages easily. At the moment, I do not have clang. Having said that, I am quite capable of compiling from source and can get many packages this way.
Using clang+automplete is also an option:
http://truongtx.me/2013/03/06/emacs-ccpp-autocomplete-with-clang/
Edit: I see you've edited the question indicating you have no clang. I leave this answer here regardless, in case someone else finds it useful.
Have you tried ac-source-gtags that is comes together with auto-complete package? You can also combine several sources, like described in documentation...
I have found that cedet is really underwhelming.
I would recommend using just one tool which does everything
https://github.com/Andersbakken/rtags
It underlines errors as you type as well as using smart completions. Just add this to your init file after obtaining the required emacs packages
(require 'rtags)
(require 'popup)
(require 'rtags-ac)
(setq rtags-completions-enabled t)
(rtags-enable-standard-keybindings c-mode-base-map)
(add-hook 'c++-mode-hook
(lambda ()
(setq ac-sources '(ac-source-rtags)
)))

Conflicting(?) 'FORMAT' function of emacs and SBCL

I have emacs with SLIME and SBCL. And I got stuck with the problem that emacs has definition of 'FORMAT' as format string &rest objects, so at REPL when I'm trying to evaluate something like (format t "hello"), I get error: Wrong type argument: stringp, t.
Is this the case of function to be overridden? How can I make emacs to use function defined in SBCL?
Guess that it's rather simple newbie problem, but it's really hard to google for 'format' keyword :)
Emacs Lisp and Common Lisp (SBCL is an implementation of it) are two different languages; it is as if you were asking how to call Java's System.out.println from your Emacs Lisp.
Emacs Lisp is used to extend and customize the behavior or Emacs.
Common Lisp is a general purpose programming language, of which there are several implementations, SBCL being one of them. It is not related to Emacs or Emacs Lisp (except, perhaps historically and culturally).
SLIME is a tool to talk to a running Common Lisp image from inside Emacs, you must first start it with M-x slime; after you have started SLIME, you can send forms to your running Common Lisp image (SBCL in your case) within the *slime-repl sbcl* buffer.
You will find another buffer named *scratch* where you can type and evaluate Emacs Lisp forms. Just remember that this has nothing to do with Common Lisp.
But, you need to be aware that there is an Emacs Lisp extension that adds many Common Lisp constructs to Emacs Lisp, but it is still Emacs Lisp, don't get confused if you read something about that.
Yeah it may be confusing at first, but don't worry, it's only temporal.
Edit:
I would like to add that if you are interested in Common Lisp, you should read one or all of the following books:
Common Lisp: A Gentle Introduction to Symbolic Computation
Land of Lisp
Practical Common Lisp
On the other hand, if you are interested in extending and customizing Emacs itself, you should read the following book:
http://www.gnu.org/software/emacs/emacs-lisp-intro/emacs-lisp-intro.pdf
Good luck.
After some investigation I found out that SLIME init script in .emacs config file was incorrect. So, while I was using inferior-lisp, it was not SBCL. Here's the link explaining the matter: slime-devel list.
So, I changed (setq inferior-lisp-program "/some/path/to/sbcl/executable.exe") to (setq inferior-lisp-program "sbcl") in config file. And that got me to SBCL in it's perfect nature :)

Using Emacs as an IDE

Currently my workflow with Emacs when I am coding in C or C++ involves three windows. The largest on the right contains the file I am working with. The left is split into two, the bottom being a shell which I use to type in compile or make commands, and the top is often some sort of documentation or README file that I want to consult while I am working. Now I know there are some pretty expert Emacs users out there, and I am curious what other Emacs functionally is useful if the intention is to use it as a complete IDE. Specifically, most IDEs usually fulfill these functions is some form or another:
Source code editor
Compiler
Debugging
Documentation Lookup
Version Control
OO features like class lookup and object inspector
For a few of these, it's pretty obvious how Emacs can fit these functions, but what about the rest? Also, if a specific language must be focused on, I'd say it should be C++.
Edit: One user pointed out that I should have been more specific when I said 'what about the rest'. Mostly I was curious about efficient version control, as well as documentation lookup. For example, in SLIME it is fairly easy to do a quick hyperspec lookup on a Lisp function. Is there a quick way to look up something in C++ STL documentation (if I forgot the exact syntax of hash_map, for example)?
You'll have to be specific as to what you mean by "the rest". Except for the object inspector (that I"m aware of), emacs does all the above quite easily:
editor (obvious)
compiler - just run M-x compile and enter your compile command. From there on, you can just M-x compile and use the default. Emacs will capture C/C++ compiler errors (works best with GCC) and help you navigate to lines with warnings or errors.
Debugging - similarly, when you want to debug, type M-x gdb and it will create a gdb buffer with special bindings
Documentation Lookup - emacs has excellent CScope bindings for code navigation. For other documentation: Emacs also has a manpage reader, and for everything else, there's the web and books.
version control - there are lots of Emacs bindings for various VCS backends (CVS, SCCS, RCS, SVN, GIT all come to mind)
Edit: I realize my answer about documentation lookup really pertained to code navigation. Here's some more to-the-point info:
Looking up manpages, info manuals, and Elisp documentation from within emacs
Looking up Python documentation from within Emacs.
Google searching will no doubt reveal further examples.
As the second link shows, looking up functions (and whatever) in other documentation can be done, even if not supported out of the box.
I have to recommend Emacs Code Browser as a more "traditional" IDE style environment for emacs.
EDIT: I also now recommend Magit highly over the standard VCS interface in emacs.
Instead of running a make command in the shell window, have you tried M-x compile? It will run your make command, display errors, and in many cases make it very easy to jump to the line of code that caused the error if the output includes filenames and line numbers.
If you're a fan of IDEs, you might also want to look at emacs' speedbar package (M-x speedbar). And, if you haven't already, learn about how to use tags tables to navigate your code.
There are corners of emacs that once discovered make you more productive in ways you never thought of. As others have mentioned, using tags is a fantastic and fast way to zoom around your source code and using M-/ (dabbrev-expand) often does exactly what you expect when completing a variable name.
Using occur is useful to get a buffer with all occurences of a regular expression in a buffer. That's really handy when refactoring code and looking for fragments of code or uses of variables, or if you use TODO markers in your source files and you want to visit them all.
flush-lines, sort-numeric-fields, replace-regexp and rectangle functions can be really useful for taking a dump from some tool and converting it to useful data such as an elisp program or a comma delimited spreadsheet.
I wrote a page about IDE like things you can do with emacs
http://justinsboringpage.blogspot.com/2007/09/11-visual-studio-tricks-in-emacs.html
Learning elisp is a another great way to answer for yourself what else emacs can do beyond what a typical IDE can do.
For example I've blogged about writing Perforce helper functions like blame (writing your own means you can make it behave exactly as you want)...
http://justinsboringpage.blogspot.com/2009/01/who-changed-line-your-working-on-last.html
I've also written code that dynamically creates comments for a function at point, that matches the coding standards I'm working with.
None of my elisp code is particularly great, and most of it exists already in libraries, but it's really useful to be able to make emacs do custom stuff that just comes up during a working day.
You can find detailed description of emacs & version control integration on my site. I'm also working on article about using Emacs as Development Environment for many languages - C/C++, Java, Perl, Lisp/Scheme, Erlang, etc...
For version control, there are several things that you can use, depending on what version control system you use. But some of the functionality is common to all of them.
vc.el is the built-in way to handle version control at a file level. It has backends for most version control systems. For instance, the Subversion backend comes with Emacs, and there are git backends and others available from other sources.
The most useful command is C-x v v (vc-next-action) that does the appropriate next action for the file you are visiting. This might mean updating from the repository or commiting your changes, vc.el also rebinds C-x C-q to check in and out files if you are using a system that needs it (like RCS).
Other very useful commands are C-x v l and C-x v = that show you the log and current diff for the file you are using.
But for real productivity, you should avoid using the single-file vc.el commands other than for simple things. There are several packages that can give you an overview of the status of your whole tree, and give you more power, and not to mention the ability to create coherent commits spanning several files.
Most of these are heavily influenced or based on the original pcl-cvs/pcvs for CVS. There are even two of them that comes with subversion, psvn.el and dsvn.el. There are packages for git etc.
Okay, everyone here is giving perfect hints to make emacs a great IDE.
But anyone should keep in mind that, when you customize your emacs with a lot of extension (especially with the ones for type-checking on the fly, function definition lookups etc) your emacs will load very, very slow for an editor.
To workaround this, I would highly recommend to use emacs in server mode.
It is pretty simple to use, no need to customize your init file.
You just need to start emacs in daemon mode;
emacs --daemon
This will create an emacs server, then you can connect it either from terminal, or from gui. I'd also recommend to create some aliases to make it easy to call.
alias ec="emacsclient -t"
alias ecc="emacsclient -c &"
# some people also prefer this but no need to fight here;
alias vi="emacsclient -t"
This way, emacs will fire up even faster than gedit, promise.
The one possible problem here, if you are running emacs daemon from your casual user, you probably can't connect emacs server as root.
So, if you need to open a file that has root access; use tramp instead. Just run your emacs client with your normal user and open files like this;
C-x C-f
/sudo:root#localhost/some/file/that/has/root/access/permissions
# on some linux distro it might be `/su:root#...`
This made my life easier, I can open my heavy customized python IDE in miliseconds this way. You may also want to add emacs --daemon to your system startup, or create a desktop file for emacsclient. Thats up to you.
More on emacs daemon and emacs client can be found at wiki;
http://www.emacswiki.org/emacs/EmacsAsDaemon
http://www.emacswiki.org/emacs/EmacsClient
I agree that you should learn about M-x compile (bind that and M-x next-error to a short key sequence).
Learn about the bindings for version control (e.g. vc-diff, vc-next-action, etc.)
Look into registers. You not only can remember locations in buffers but whole window configurations (C-x r w -- window-configuration-to-register).
A starting point (which may be non-obvious) for exploring the VC features of Emacs is M-x vc-next-action.
It does the "next logical version control operation" on the current file, depending on the state of the file and the VC backend. So if the file is not under version control, it registers it, if the file has been changed, the changes are submitted etc.
It takes a little getting used to, but I find it very useful.
Default keybinding is C-x v v
I know this is a very old post. But this question is valid for emacs beginners.
IMO the best way to use emacs as an ide is to use a language server protocol with emacs. You can find all the information about language servers in the linked website.
For a quick setup, i would urge you to go to this page eglot . IMO eglot does it's job pretty well. It integrates well with auto completions packages like company. Provides find reference, and more.
Also for a debugger, you may need specific debuggers for specific languages. You can use gdb from within emacs. Just type M-x gdb .
For compiling your code, it's best to use shell-commands. I am working on this project eproj. It's gonna take a while to complete it. But all it does is maps shell command to project type. And builds you project via shell. It does the same to execute command. I may need help completing this project. It's not ready for use, but if you know a bit of elisp you can go through the code.
That aside, it's always best to use the emacs compile command.
For version control, I haven't yet seen any other package which can match the power of magit. It's specific to git. Also for git there is another package git-timemachine, which i find very useful.
Object lookup and class lookup is provided by language server protocol.
A project tree can be used for ide like interface with treemacs.
There is also a project Interaction Library called projectile.
For auto completion, I find company-mode very useful.
Truly emacs can be made to do anything.
There's a TFS.el for emacs integration into Microsoft TFS. It works with any TFS, including the TFS that runs Codeplex.com.
Basic steps to setup:
Place tfs.el in your load-path.
In your .emacs file:
(require 'tfs)
(setq tfs/tf-exe "c:\\vs2008\\common7\\ide\\tf.exe")
(setq tfs/login "/login:domain\\userid,password")
-or-
(setq tfs/login (getenv "TFSLOGIN")) ;; if you have this set
also in your .emacs file, set local or global key bindings for tfs commands. like so:
(global-set-key "\C-xvo" 'tfs/checkout)
(global-set-key "\C-xvi" 'tfs/checkin)
(global-set-key "\C-xvp" 'tfs/properties)
(global-set-key "\C-xvr" 'tfs/rename)
(global-set-key "\C-xvg" 'tfs/get)
(global-set-key "\C-xvh" 'tfs/history)
(global-set-key "\C-xvu" 'tfs/undo)
(global-set-key "\C-xvd" 'tfs/diff)
(global-set-key "\C-xv-" 'tfs/delete)
(global-set-key "\C-xv+" 'tfs/add)
(global-set-key "\C-xvs" 'tfs/status)
(global-set-key "\C-xva" 'tfs/annotate)
(global-set-key "\C-xvw" 'tfs/workitem)
compile, next-error, and previous-error are all pretty important commands for C++ development in Emacs (works great on grep output too). Etags, visit-tags-table, and find-tag are important as well. completion.el is one of the great unsung hacks of the 20th century, and can speed up your C++ hacking by an order of magnitude. Oh and let's not forget ediff.
I've yet to learn how to use version control without visiting a shell, but now that I'm running commits so much more frequently (with git) I will probably have to.
You might also find tabbar useful. It emulates the only behavior I missed when moving from Eclipse to Emacs. Bound to "," and "." for moving to the previous and next tab bar, it relives you from switching the buffer by Ctrl-x b all the time.
Unfortunately, the mentioned web page does not provide the correct version to download. Most Ubuntu versions, however, deliver it in their emacs-goodies packages.
I use emacs on Windows. the compile module is nice, but I wanted compile to be smarter about the compile command line it suggests. It's possible to use "File Variables" to specify compile-command, but I wanted something a little smarter than that. So I wrote a little function to help out. It guesses the compile command to use, to prompt the user with, when running compile.
The guess function looks for a vbproj or csproj or sln file, and if found, it suggests msbuild. Then it looks at the buffer file name, and depending on that, suggests different things. A .wxs file means it's a WIX project, and you likely want to build an MSI, so the guess logic suggests an nmake command for the MSI. If it's a Javascript module, then the suggestion is to run jslint-for-wsh.js to lint the .js file. As a fallback, it suggests nmake.
The code I use looks like this:
(defun cheeso-guess-compile-command ()
"set `compile-command' intelligently depending on the
current buffer, or the contents of the current directory."
(interactive)
(set (make-local-variable 'compile-command)
(cond
((or (file-expand-wildcards "*.csproj" t)
(file-expand-wildcards "*.vcproj" t)
(file-expand-wildcards "*.vbproj" t)
(file-expand-wildcards "*.shfbproj" t)
(file-expand-wildcards "*.sln" t))
"msbuild ")
;; sometimes, not sure why, the buffer-file-name is
;; not set. Can use it only if set.
(buffer-file-name
(let ((filename (file-name-nondirectory buffer-file-name)))
(cond
;; editing a .wxs (WIX Soluition) file
((string-equal (substring buffer-file-name -4) ".wxs")
(concat "nmake "
;; (substring buffer-file-name 0 -4) ;; includes full path
(file-name-sans-extension filename)
".msi" ))
;; a javascript file - run jslint
((string-equal (substring buffer-file-name -3) ".js")
(concat (getenv "windir")
"\\system32\\cscript.exe c:\\users\\cheeso\\bin\\jslint-for-wsh.js "
filename))
;; something else - do a typical .exe build
(t
(concat "nmake "
(file-name-sans-extension filename)
".exe")))))
(t
"nmake "))))
(defun cheeso-invoke-compile-interactively ()
"fn to wrap the `compile' function. This simply
checks to see if `compile-command' has been previously set, and
if not, invokes `cheeso-guess-compile-command' to set the value.
Then it invokes the `compile' function, interactively."
(interactive)
(cond
((not (boundp 'cheeso-local-compile-command-has-been-set))
(cheeso-guess-compile-command)
(set (make-local-variable 'cheeso-local-compile-command-has-been-set) t)))
;; local compile command has now been set
(call-interactively 'compile))
;; in lieu of binding to `compile', bind to my monkeypatched function
(global-set-key "\C-x\C-e" 'cheeso-invoke-compile-interactively)
I tried doing this as "before advice" for the compile function but couldn't get it to work satisfactorily. So I defined a new function and bound it to the same keystroke combination I have been using for compile.
EDIT there is now "smarter-compile.el" which takes this idea one step further.
In the recent years, Clang became an important part of the Emacs C++ support. Atila Neves had a talk on CppCon 2015:
"Emacs as a C++ IDE"
It is a 16 minute talk, where he shows solutions for the following topics:
Jump to definition
Auto-completion
On-the-fly syntax highlighting
Find file in project
Slides can be found here.
On documentation lookup: that depends on your programming language(s).
C libraries and system calls are typically documented in man pages. For that you can use M-x man. Some things may be documented better in info pages; use M-x info.
For elisp itself, use C-h f. For python, use >>> help(<function, class, module>) in the interpreter.
I find that most other languages offer documentation in html form. For that, try an embedded browser (I use w3m). Set your BROWSER environment variable to a wrapper script around emacsclient -e "(w3m-goto-url-new-session \"$#\")" (on *nix), in case something might open a browser and you want it opened inside emacs.
Try lsp-mode. Now you can use other IDE functionality inside emacs connecting to server. Look for more info: lsp-mode
In the Unix or X windows style, I don't know that there is an integrated IDE that works for everything.
For interacting with debuggers, just one component of an IDE, consider realgud. The other thing it has that I find useful are parsers for location messages, so that if you have a call stack trace and want to edit at a particular place in the callstack, this front-end interface will can do that.
By far this program could use improvement. But then it could also use people working on it to improve it.
Disclaimer: I work on realgud