How to run Common Lisp code with Slime in Emacs Lisp - emacs

For some reason I wrote some Common Lisp code to do what I want. And I use the QuickLisp and the Slime. Now I hope to integrate with the Emacs Lisp.
I tried to use
(slime)
(slime-eval-region start end)
...
in my el file but it doesn't work.
I just to run the Common Lisp code and catch the return value , that is all.
So what should I do?

If I understood you correctly, you want to take a Common Lisp code as an Elisp string,
eval it within SLIME and obtain the output as an Elisp string plus side-effects.
You can do this with this setup code:
(require 'slime)
(defun lispy--eval-lisp (str)
"Eval STR as Common Lisp code."
(unless (slime-current-connection)
(let ((wnd (current-window-configuration)))
(slime)
(while (not (and (slime-current-connection)
(get-buffer-window (slime-output-buffer))))
(sit-for 0.2))
(set-window-configuration wnd)))
(let (deactivate-mark)
(cadr (slime-eval `(swank:eval-and-grab-output ,str)))))
or alternatively just (require 'le-lisp) if you have installed lispy package from MELPA or
github.
Here's a sample usage in *scratch*:
(lispy--eval-lisp "(load \"~/quicklisp/setup\")")
;; "T"
(lispy--eval-lisp "(ql:quickload 'png)")
;; "(PNG)"
(lispy--eval-lisp "(png:make-image 5 5 1)")
;; "#3A(((0) (0) (0) (0) (0))
;; ((0) (0) (0) (0) (0))
;; ((0) (0) (0) (0) (0))
;; ((0) (0) (0) (0) (0))
;; ((0) (0) (0) (0) (0)))"

Related

How to hide the symbol $ when highlighting LaTeX equations in Emacs Org-mode?

I know that in Org-mode, the emphasis markers like *, ~, =, +, _ can be hidden by this setting: (setq org-hide-emphasis-markers t).
I wonder if there is any option that enables hiding the markers like $ or \(, \) of LaTeX?
This will be useful when LaTeX math equations can be highlighted by setting:
(setq org-highlight-latex-and-related '(latex script entities))
Update 1
I tried the solution proposed by #Thomas on a fresh emacs -q but somehow the symbol $ is still not hidden, while other markers like *,+ are. \
Not sure if there is something wrong with my Emacs? I'm using Org 9.3 of Emacs 27.1
Update 2
The solution of Thomas does work for Emacs 25.2!
But somehow, there is a major change in Emacs 26.2, 26.3, 27.1 that breaks this feature... :(
Update 3
Since the solution suggested by Thomas doesn't work with recent Emacs (26 or newer), I finally came up with a quick solution by customizing the function org-do-latex-and-related of Org-mode.
(defun org-do-latex-and-related (_limit)
"Highlight LaTeX snippets and environments, entities and sub/superscript.
Stop at first highlighted object, if any. Return t if some
highlighting was done, nil otherwise."
(when (org-string-nw-p org-latex-and-related-regexp)
(catch 'found
(while (re-search-forward org-latex-and-related-regexp
nil t) ;; on purpose, we ignore LIMIT
(unless (cl-some (lambda (f) (memq f '(org-code org-verbatim underline
org-special-keyword)))
(save-excursion
(goto-char (1+ (match-beginning 0)))
(face-at-point nil t)))
(let* ((offset (if (memq (char-after (1+ (match-beginning 0)))
'(?_ ?^))
1
0))
(start (+ offset (match-beginning 0)))
(end (match-end 0)))
(if (memq 'native org-highlight-latex-and-related)
(org-src-font-lock-fontify-block "latex" start end)
(font-lock-prepend-text-property start end
'face 'org-latex-and-related))
;;<<<<<<<<<<<<<<<<<<<<<
;; my code starts here
(when (and org-hide-emphasis-markers (< (+ start 4) end))
(cond ((member (buffer-substring start (+ start 2)) '("$$" "\\("))
(add-text-properties start (+ start 2) '(invisible org-link)))
((string= (buffer-substring (1+ start) (+ start 2)) "$")
(add-text-properties (1+ start) (+ start 2) '(invisible org-link))))
(cond ((member (buffer-substring end (- end 2)) '("$$" "\\)"))
(add-text-properties end (- end 2) '(invisible org-link)))
((string= (buffer-substring (1- end) (- end 2)) "$")
(add-text-properties (1- end) (- end 2) '(invisible org-link)))))
;; my code ends here
;;>>>>>>>>>>>>>>>>>>>>>
(add-text-properties (+ offset (match-beginning 0)) (match-end 0)
'(font-lock-multiline t)))
(throw 'found t)))
nil)))
If anyone interested in this feature, you can place the above function somewhere in your Emacs configuration file, after Org-mode is loaded, so that the new org-do-latex-and-related will override the original one of Org-mode.
Here is what I obtained using the code above:
An alternative approach is to not hide the $ symbol at all and instead use org-fragtog. It automatically toggles org-mode latex fragment previews as the cursor enters and exits them.
However, when you open a file with equations it will only toggle the preview of an equation as the cursor enters and leaves the equation. I also have a keybinding (f5) for org-latex-preview. If I open an org-mode file with many equations I can type C-u C-u f5 to toggle latex preview on all equations in the buffer. If I want to change some equation I can just move the cursor there and org-fragtog-mode will turn-off the preview. Then I can edit the equation and the cursor leaves the equation the preview will be automatically enabled again.
This also works correctly when org-highlight-latex-and-related is set to any of the possible choices as well as when you use prettify-symbols-mode.
Customize the variable org-emphasis-alist and add $ as an additional maker with the default values for all customization options. To do so, type
M-x customize-variable [RET] org-emphasis-alist [RET]
Then go to the bottom of the customization buffer, click on the last INS, and insert a dollar sign under Marker character:.
Finally, click on State to make this change permanent either for the current editing session only or also for all future sessions.
NOTE that you have to restart org-mode by typing M-x org-mode again in order for this change to take effect.

How to evaluate Common Lisp code in non-slime buffers?

I'd like to be able to get my SBCL 1.4.5 (Linux x86_64)
Emacs 'inferior-lisp-process' to evaluate a S-Expression (sexp)
in some Emacs buffer that is not the 'slime' buffer - I have
latest quicklisp and slime-2.20 .
I thought this was exactly the same issue as in :
How to run Common Lisp code with Slime in Emacs Lisp
but it is not - my issue is that when I try to run 'slime-eval' or
any slime 'run in inferior-lisp-process' method ALL symbols seem to be
being looked up in ONLY in the SWANK-IO-PACKAGE namespace :
In my Emacs '*scratch*' buffer:
(slime-eval '(symbolp '+) "CL-USER")
Produces a backtrace error:
The function SWANK-IO-PACKAGE::SYMBOLP is undefined.
[Condition of type UNDEFINED-FUNCTION]
Restarts:
0: [CONTINUE] Retry calling SWANK-IO-PACKAGE::SYMBOLP.
1: [USE-VALUE] Call specified function.
2: [RETURN-VALUE] Return specified values.
3: [RETURN-NOTHING] Return zero values.
4: [*ABORT] Return to SLIME's top level.
5: [ABORT] abort thread (#<THREAD "worker" RUNNING {100262C8E3}>)
Backtrace:
0: ("undefined function" SWANK-IO-PACKAGE::+)
1: (SB-INT:SIMPLE-EVAL-IN-LEXENV \
(SWANK-IO-PACKAGE::SYMBOLP (QUOTE SWANK-IO-PACKAGE::+)) \
#<NULL-LEXENV>)
2: (EVAL (SWANK-IO-PACKAGE::SYMBOLP (QUOTE SWANK-IO-PACKAGE::+)))
It makes no difference whether I do :
(slime-eval '(symbolp :+) "CL-USER")
OR
(slime-eval '(symbolp '+))
I still get the same error because '+ and :+ are
always looked up only in the SWANK-IO-PACKAGE namespace.
I found this by simply trying to run, for my first test:
(slime-eval '(+ 2 2) "CL-USER")
which prints in the output buffer another backtrace
The function SWANK-IO-PACKAGE::+ is undefined.
[Condition of type UNDEFINED-FUNCTION]
I did try the code snippet from Question #22456086 :
(require 'slime)
(defun slrepl (str)
"Eval STR as Common Lisp code."
(unless (slime-current-connection)
(let ((wnd (current-window-configuration)))
(slime)
(while (not (and (slime-current-connection)
(get-buffer-window (slime-output-buffer))))
(sit-for 0.2))
(set-window-configuration wnd)))
(let (deactivate-mark)
(cadr (slime-eval `(swank:eval-and-grab-output ,str)))))
So doing:
(slrepl '(symbol-function '+))^X^E
Still results in :
The function SWANK-IO-PACKAGE::SYMBOL-FUNCTION is undefined.
[Condition of type UNDEFINED-FUNCTION]
Access to the default SB_INT namespace seems to be denied .
How to enable it for such cases ?
I'd like to be able to send forms to and read results from the same emacs inferior-lisp-process (sbcl) from any buffer, not just from the slime
'slime repl sbcl' buffer . Is there any way to do this?
Obviously, I can write an Emacs Lisp function to switch-to the
slime repl buffer and evaluate in that buffer.
Of course, all the above examples, eg. (eval '(symbolp '+)) ,
work fine in the slime-repl buffer. I guess there is no way
around switching-to the slime-repl buffer?
This might clarify:
In 'scratch' :
(slime-eval '(SB-INT:symbolp 'SB-INT:+) "CL-USER")^X^E
In slime output buffer:
Invalid protocol message:
The symbol "SYMBOLP" is not external in the SB-INT package.
Line: 1, Column: 26, File-Position: 26
Stream: #<SB-IMPL::STRING-INPUT-STREAM {1002A1CD63}>
(:emacs-rex (SB-INT:symbolp (quote SB-INT:+)) "CL-USER" t 78)
So, in the slime-repl buffer, I can do:
CL-USER> (PROGN (IN-PACKAGE "COMMON-LISP-USER") (+ 2 2))
4
CL-USER> (PROGN (IN-PACKAGE "SB-IMPL") (symbol-function '+))
#<FUNCTION +>
CL-USER> (PROGN (IN-PACKAGE "SB-IMPL") (symbol-function '+))
#<FUNCTION +>
SB-IMPL> (PROGN (IN-PACKAGE "SB-INT") (symbol-function '+))
#<FUNCTION +>
But if I try to run the same 'slime-eval' function in any
other buffer, eg. 'scratch' :
(slime-eval '(PROGN (COMMON-LISP-USER:IN-PACKAGE "COMMON-LISP-USER")
(symbol-function '+)) :COMMON-LISP-USER)
Invalid protocol message:
The symbol "IN-PACKAGE" is not external in the
COMMON-LISP-USER package.
Line: 1, Column: 46, File-Position: 46
I have tried ALL the likely PACKAGE names listed above in the
slime-eval with same results.
The same thing happens whether I use the 'slrepl' code snippet or just plain
slime-eval - no lisp standard syntax symbols are available. Do I need to
load the lisp syntax table or something ?
RE: can I switch to slime repl buffer and do it ? : NO ! :
(require 'slime)
(let ((slbuf (get-buffer "*slime-repl sbcl*")))
(if (eq nil slbuf)
(error "please start slime (M-x slime)")
(progn (set-buffer slbuf)(slime-eval '(+ 2 2) "COMMON-LISP-USER"))
)
)^X^E
Still results in :
The function SWANK-IO-PACKAGE::+ is undefined.
[Condition of type UNDEFINED-FUNCTION]
I am a rusty / returning LISP user and new to SBCL and slime .
I'd really like to integrate Emacs' great Editing and File management
& interacation facilitties with external CL XML & HTML generation & parsing
tools. But to start, I'd just like to get to the root of this problem...
Common Lisp symbols like + and symbolp are in the COMMON-LISP package. Short name CL. These symbols are usually not exported from package CL-USER. Thus symbolp can be referenced as cl:symbolp. These symbols are accessible in package CL-USER, but not exported from there. Thus you can also reference cl:symbolp as cl-user::symbolp -> note the two colons.
CALLING IN-PACKAGE in a form does not have an effect on the form itself, since the form is already read. Though it has an effect calling reader functions or functions like find-symbol.
CL-USER 5 > (defpackage "FOO" (:use))
#<The FOO package, 0/16 internal, 0/16 external>
CL-USER 6 > (progn (in-package "FOO")
(list 'bar (read-from-string "BAR")))
(COMMON-LISP-USER::BAR BAR) ; we now print from package "FOO"
Using SLIME-EVAL in Emacs Lisp
Best use it with a form, that reads the expression on the Common Lisp side and does not involve the Emacs Lisp reader/printer:
ELISP> (slime-eval '(cl:eval (cl:read-from-string "(+ 1 2)")) "CL-USER")
3 (#o3, #x3, ?\C-c)
ELISP> (slime-eval '(cl:eval (cl:read-from-string "'foo")) "CL-USER")
common-lisp-user::foo
But here you see that the result is brought back into Emacs Lisp via the Emacs Lisp reader - where packages don't exist.
Thus SLIME-EVAL makes very little sense as a simple remote execution interface...
This now works! Thanks !
(require 'slime)
(defun CL$ (str)
(let ((slbuf (get-buffer "*slime-repl sbcl*")))
(if (eq nil slbuf)
(error "Please start slime (M-x slime).")
(progn
(set-buffer slbuf)
(slime-eval str "CL")
)
)
)
)
(CL$ '(cl:+ 2 2))
=> 4
But I don't fully understand why I have to prepend all symbols with CL or
why this still does not work:
(slime-eval '(+ 2 2) "CL")
but this does:
(slime-eval '(cl:+ 2 2) "CL")
I thought the third parameter was meant to be made into the current package?
So why do I have to append 'cl' to every symbol .
But thanks for the help, and an otherwise great slime + sbcl .

Difference between a normal buffer and a space prefix buffer in Emacs?

By a space prefix buffer, I mean buffers with names that start with a space. Not sure what's the official jargon for such buffers.
I thought the only difference of space prefix buffers were that undo was disabled on them, but there seem to be other differences which are causing the package htmlize to react differently to space prefix buffers.
(require 'htmlize)
;; function to write stuff on current buffer and call htmlize-region
(defun my-test-htmlize ()
(insert "1234567")
(emacs-lisp-mode)
;; (put-text-property 1 2 'font-lock-face "bold")
(put-text-property 3 4 'font-lock-face 'bold)
(with-current-buffer (htmlize-region (point-min)
(point-max))
(buffer-string)))
;; function that makes a (failed) attempt to make current buffer behave like a normal buffer
(defun my-make-buffer-normal ()
(buffer-enable-undo))
;; like with-temp-buffer, except it uses a buffer that is not a space prefix buffer.
(defmacro my-with-temp-buffer-with-no-space-prefix (&rest body)
(declare (indent 0) (debug t))
(let ((temp-buffer (make-symbol "temp-buffer")))
`(let ((,temp-buffer (generate-new-buffer "*tempwd2kemgv*")))
(with-current-buffer ,temp-buffer
(unwind-protect
(progn ,#body)
(and (buffer-name ,temp-buffer)
(kill-buffer ,temp-buffer)))))))
;; In a normal buffer, bold face is htmlized.
(my-with-temp-buffer-with-no-space-prefix
(my-test-htmlize))
;; In a space prefix buffer, bold face is not htmlized.
(with-temp-buffer
(my-test-htmlize))
;; Bold face is still not htmlized.
(with-temp-buffer
(my-make-buffer-normal)
(my-test-htmlize))
Leading spaces indicate ephemeral or uninteresting buffers. These have no undo history, and many commands place these buffers less prominently, or even ignore them completely. See Emacs Lisp Reference, Buffer Names:
Buffers that are ephemeral and generally uninteresting to the user have names starting with a space, so that the list-buffers and buffer-menu commands don't mention them (but if such a buffer visits a file, it is mentioned). A name starting with space also initially disables recording undo information; see Undo.
There are no further differences on built-in commands, but any command is free to handle these buffers in a special way. You probably need to consult the htmlize sources to determine the cause of the different behavior.
Found another difference of buffers with names starting with a space. Additional manual font lock will not work with such buffers.
(defmacro my-with-temp-buffer-with-name (buffername &rest body)
(declare (indent 1) (debug t))
(let ((temp-buffer (make-symbol "temp-buffer")))
`(let ((,temp-buffer (generate-new-buffer ,buffername)))
(with-current-buffer ,temp-buffer
(unwind-protect
(progn ,#body)
(and (buffer-name ,temp-buffer)
(kill-buffer ,temp-buffer)))))))
(my-with-temp-buffer-with-name "*temp*"
(insert "1234567")
(emacs-lisp-mode)
(put-text-property 3 4 'font-lock-face 'bold)
(print (next-single-property-change 1 'face)))
;; => 3
(my-with-temp-buffer-with-name " *temp*" ; with a space prefix
(insert "1234567")
(emacs-lisp-mode)
(put-text-property 3 4 'font-lock-face 'bold)
(print (next-single-property-change 1 'face)))
;; => nil
Update: The reason the additional font lock does not work is because font-lock-mode actively avoids working with such buffers (see definition of font-lock-mode) One way to make it work is to call font-lock-default-function directly.
(my-with-temp-buffer-with-name " *temp*" ; with a space prefix
(insert "1234567")
(emacs-lisp-mode)
(put-text-property 3 4 'font-lock-face 'bold)
(font-lock-default-function t) ; <==
(print (next-single-property-change 1 'face)))
;; => 3

Why is clojure-mode replacing fn with some curly f character?

I've just started using emacs starter kit & clojure-mode. Now, when I type or paste '(fn' into a buffer in clojure mode, the 'fn' characters get replaced in the window with a slightly curly lower case f. The buffer is saved correctly, but it's extremely annoying, especially as I discovered the feature the hard way - puzzling over someone's 'impossible' code snippet and editing it down to a one-liner before light dawned. Any idea why it does this, or more importantly, how to switch it off?
It can be turned off by adding the following line to your init.el after loading starter-kit-lisp.
(remove-hook 'clojure-mode-hook 'esk-pretty-fn)
Then re-load Emacs for it to take effect.
Sorry to answer my own question. It's in starter-kit-lisp.el. Look for the line starting (eval-after-load 'clojure-mode.
In emacs live you can disable this behaviour with the following:
In ~/.emacs.d/packs/live/clojure-pack/config/clojure-conf.el comment these lines:
;;(eval-after-load 'clojure-mode
;; '(font-lock-add-keywords
;; 'clojure-mode `(("(\\(fn\\)[\[[:space:]]"
;; (0 (progn (compose-region (match-beginning 1)
;; (match-end 1) "λ")
;; nil))))))
;;
;;(eval-after-load 'clojure-mode
;; '(font-lock-add-keywords
;; 'clojure-mode `(("\\(#\\)("
;; (0 (progn (compose-region (match-beginning 1)
;; (match-end 1) "ƒ")
;; nil))))))
;;
;;(eval-after-load 'clojure-mode
;; '(font-lock-add-keywords
;; 'clojure-mode `(("\\(#\\){"
;; (0 (progn (compose-region (match-beginning 1)
;; (match-end 1) "∈")
;; nil))))))
Restart emacs and there are no more fancy symbols.

What is the folding method corresponding to {{{ in Emacs?

I have used the following as comments in my .emacs
// {{{
// }}}
My .emacs
;; Basic Characteristics// {{{*/
(setq c-basic-offset 4) ; indents 4 chars
(setq tab-width 4) ; and 4 char wide for TAB
(setq indent-tabs-mode nil) ; And force use of spaces
(turn-on-font-lock) ; same as syntax on in Vim
(setq inhibit-splash-screen t) ; hide welcome screen// }}}*/
;;;; For Emacs' org -mode// {{{*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The following lines are always needed. Choose your own keys.
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(global-font-lock-mode 1) ; for all buffers
(add-hook 'org-mode-hook 'turn-on-font-lock) ; Org buffers only
;; This is needed for Emacs 22, not for 23
(transient-mark-mode 1)
;; To load Lisp files
;; includes only one folder
;; (add-to-list 'load-path "~/.lisp")
;// }}}*/
;; to include all subdirectories too// {{{*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 1. color theme
;;; 2. Google hyperlinks
;;; this code includes only one folder
(let ((base "/Users/Masi/.lisp"))
(add-to-list 'load-path base)
(dolist (f (directory-files base))
(let ((name (concat base "/" f)))
(when (and (file-directory-p name)
(not (equal f ".."))
(not (equal f ".")))
(add-to-list 'load-path name)))))
;// }}}*/
; customize hs-minor-mode// {{{*/
(add-hook 'c-mode-common-hook
(lambda()
(local-set-key (kbd "C-c <right>") 'hs-show-block)
(local-set-key (kbd "C-c <left>") 'hs-hide-block)
(local-set-key (kbd "C-c <up>") 'hs-hide-all)
(local-set-key (kbd "C-c <down>") 'hs-show-all)
(hs-minor-mode t)))
;// }}}*/
;; Folds// {{{*/
; to enable folding mode
(load "folding" 'nomessage 'noerror)
(folding-mode-add-find-file-hook)t
;;{{{ LaTeX mode stuff
(add-hook 'TeX-mode-hook
'(lambda ()
(LaTeX-math-mode)
(turn-on-reftex)))
;;// }}}*/
I get the following error
Loading encoded-kb...done
An error has occurred while loading `/Users/Masi/.emacs':
error: Too many arguments
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
In debug mode, it says
Debugger entered--Lisp error: (error "Too many arguments")
(defvar folding-package-url-location "Latest folding is available at http://cvs.xemacs.org/-xemacs-p (or (boundp 'xemacs-logo)\n $
eval-buffer(#<buffer *load*<2>> nil "/Users/Masi/.lisp/folding.el" nil t) ; Reading at buffer position 35362
load-with-code-conversion("/Users/Masi/.lisp/folding.el" "/Users/Masi/.lisp/folding.el" t t)
load("folding" nomessage noerror)
eval-buffer(#<buffer *load*> nil "/Users/Masi/.emacs" nil t) ; Reading at buffer position 2224
load-with-code-conversion("/Users/Masi/.emacs" "/Users/Masi/.emacs" t t)
load("~/.emacs" t t)
#[nil "^H\205\276^# \306=\203^Q^#\307^H\310Q\202A^# \311=\2033^#\312\307\313\314#\203#^#\315\202A^#\312\307\313\316#\203/^#\317\202A^#\315\202A^# \32$
command-line()
normal-top-level()
My ~/.lisp/folding.el
;;; folding.el --- A folding-editor-like minor mode.
;; This file is not part of Emacs
;; Copyright (C) 2000-2009
;; Jari Aalto
;; Copyright (C) 1995, 1996, 1997, 1998, 1999
;; Jari Aalto, Anders Lindgren.
;; Copyright (C) 1994
;; Jari Aalto
;; Copyright (C) 1992, 1993
;; Jamie Lokier, All rights reserved.
;;
;; Author: Jamie Lokier <jamie A T imbolc.ucc dt ie>
;; Jari Aalto <jari aalto A T cante dt net>
;; Anders Lindgren <andersl A T csd.uu dt se>
;; Maintainer: Jari Aalto <jari aalto A T cante dt net>
;; Created: 1992
;; Keywords: tools
;;
;; [Latest XEmacs CVS tree commit and revision]
;; VCS-Version: $Revision: 3.42 $
;; VCS-URL: http://savannah.nongnu.org/projects/emacs-tiny-tools/
;; VCS-Date: $Date: 2007/05/07 10:50:05 $
;;
;; [Latest devel: Savannah emacs-tiny-tools revision]
;; Version: git 56b3089
(defconst folding-version-time "2009.0220.1404"
"Last edit time in format YYYY.MMDD.HHMM.")
;;{{{ GPL
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation,
;; or (at your option) any later version.
;;
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with program. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;
;; Visit <http://www.gnu.org/copyleft/gpl.html> for more information
;;}}}
;;; Commentary:
;;{{{ Introduction
;; Preface
;;
;; This package provides a minor mode, compatible with all major
;; editing modes, for folding (hiding) parts of the edited text or
;; program.
;;
;; Folding mode handles a document as a tree, where each branch
;; is bounded by special markers `{{{' and `}}}'. A branch can be
;; placed inside another branch, creating a complete hierarchical
;; structure.
;;
;; Folding mode can CLOSE a fold, leaving only the initial `{{{'
;; and possibly a comment visible.
;;
;; It can also ENTER a fold, which means that only the current
;; fold will be visible, all text above `{{{' and below `}}}'
;; will be invisible.
;;
;; Please note, that the maintainers do not recommend to use only
;; folding for you your code layout and navigation. Folding.el is
;; on its best when it can "chunk" large sections of code inside
;; folds. The larger the chunks, the more the usability of
;; folding will increase. Folding.el is not meant to hide
;; individual functions: you may be better served by hideshow.el
;; or imenu.el (which can parse the function indexes)
;;}}}
;;{{{ Installation
;; Installation
;;
;; To install Folding mode, put this file (folding.el) on your
;; Emacs `load-path' (or extend the load path to include the
;; directory containing this file) and optionally byte compile it.
;;
;; The best way to install folding is the autoload installation,
;; so that folding is loaded into your emacs only when you turn on
;; `folding-mode'. This statement speeds up loading your .emacs
;;
;; (autoload 'folding-mode "folding" "Folding mode" t)
;; (autoload 'turn-off-folding-mode "folding" "Folding mode" t)
;; (autoload 'turn-on-folding-mode "folding" "Folding mode" t)
;;
;; But if you always use folding, then perhaps you want more
;; traditional installation. Here Folding mode starts
;; automatically when you load a folded file.
;;
;; ;; (setq folding-default-keys-function
;; ;; 'folding-bind-backward-compatible-keys)
;;
;; (if (load "folding" 'nomessage 'noerror)
;; (folding-mode-add-find-file-hook))
;;
;; Folding uses a keymap which conforms with the new Emacs
;; (started 19.29) style. The key bindings are prefixed with
;; "C-c#" instead of old "C-c". To use the old keyboard bindings,
;; uncomment the lines in the the above installation example
;;
;; The same folding marks can be used in `vim' editor command
;; "set fdm=marker".
;;
;; Uninstallation
;;
;; To remove folding, call `M-x' `folding-uninstall'.
;;
;; To read the manual
;;
;; At any point you can reach the manual with `M-x'
;; `finder-commentary' RET folding RET.
;;}}}
;;{{{ DOCUMENTATION
;; Compatibility
;;
;; Folding supports following Emacs flavors:
;;
;; Unix Emacs 19.28+ and Win32 Emacs 19.34+
;; Unix XEmacs 19.14+ and Win32 XEmacs 21.0+
;;
;; Compatibility not for old NT Emacs releases
;;
;; NOTE: folding version starting from 2.47 gets around this bug
;; by using adviced kill/yank functions. The advice functions are
;; only instantiated under problematic NT Emacs versions.
;;
;; Windows NT/9x 19.34 - 20.3.1 (i386-*-nt4.0) versions contained
;; a bug which affected using folding. At the time the bug was
;; reported by Trey Jackson <trey A T cs berkeley edu>
;;
;; If you kill folded area and yank it back, the ^M marks are
;; removed for some reason.
;;
;; Before kill
;; packages or modes
;;
;; Folding.el was designed tofor big files. Sometimes people misunderstand the
;; better job. Trying to wrap
;; individual functions insis not where folding is
;; it's best. Grouping several f logical fold-block
;; in the other is. So, to choose a our need,
;; here are some suggestions,:
;;
;; o Naation of imenu.el, speedbar.el and
;; hideshow.el
;; ng.el
;; o For text, `outline-mode' is more non-intrusive.
;; Look at Emacs NEWS file (`C-x' `n') and you can se: `M-x' `folding-mode'
;; `RET'. The mode line should cont When loading a document containing fold marks, Folding mode ised. For example when
;; loading my init file, only the follines
;; of comments) are visible:
;;
;; ;;{{{ Ge ;;{{{ Keyboard...
;; ;;{{{ Packages...
;; ;; ;;{{{ Minor modes...
;; ;;{{{ Debug...
;;
;t entering,
;; use `C-c # C-s', which produces this displa
;; ;;}}}
;;
;; To show everything, just as the fook like if
;; Folding mode hadn't been activated, give thT', normally bound to `C-c' `#'
;; `C-o'. To close all foevel, the
;; command `folding-whole-buffer' could be used.ouse support
;;
;; Folding mode v2.0 introduced mouse support. Folds can be shown
;; or hidden by simply clicking ondidn't click on a
;; fold mark.
;;
;; The menu
;;
;; placed in the "Tools" menu. Should no Tools menu exist
;; he menu will be placed in the menu bar.
;;
;; ISearch
;;
;; incremental search (C-s) facilities,
;; folds will be aut;;
;; Problems
;;
;; Uneven fold marks
;;
;; Oops, I ;;{{{
;; ;;}}}
;;
;; folding-whole-buffer d whole buffer
;;
;; If you call commands `folding-open-bufd
;; `folding-whole-buffer' and notice that there are open;; sections in the buffer, then you have mismatch of foldspen or closing fold mark.
;;
;; Folding and outline modes
;;
;ame as Outline mode, a major and
;; minor mode which is pahe Emacs distribution. The two
;; packages do, however, re other very much. The main
;; differences between the twore:
;;
;; o Folding mode uses explicit marks, `{{{' and `}}}', to
;; mark the beginning and the end of a branch.
;; Outline, on the other other hand, tries to use already
;; existing marks, like the `\section' string in a TeX
;; document.
;;
;; o Outline mode has no end marker which means that it is
;; impossible for text to follow a sub-branch.
;;
;; o Folding mode use the same markers for branches on all depths,
;; Outline mode requires that marks should be longer the
;; further, down in the tree you go, e.g `\chap', \section',
;; `\subsection', `\subsubsection'. This is needed to
;; distinguish the next mark at the current or higher levels
;; from a sub-branch, a problem caused by the lack of
;; end-markers.
;;
;; o Folding mode has mouse suppoyou can navigate through a
;; folded document by clicksion
;; of Outline mode has mouse support.)
;;
;; of Folding is capable of
;; automatically to open folthe the entire
;; document must be opened prior isearcutline mode is useful when the document being
;; edited coers are hard to find, except if you're happy with
;; one fn per fold.
;;
;; Future development ideas
;;
;; The planinning to rewrite the entire package.
;; Including replacithe program, written using
;; old Emacs technology (selectys or text-properties for
;; Emacs and extents for XEmacs.;;
;; It is not likely that any of this will come true coning
;; the time required to rewrite the core of the package. Since
;; the package, in it's current state, is much more powerful than
;; the original, it would be appropriate to write such package
;; from scratch instead of doing surgery on this one.
;;}}}
;;{{{ Customization
;; Customization: general
;;
;; The behavior of Folding mode is controlled mainly by a set of
;; Emacs Lisp variables. This section will discuss the most
;; useful ones, for more details please see the code. The
;; descriptions below assumes that you know a bit about how to
;; use simple Emacs Lisp and kt ~/.emacs, your
;; init file.
;;
;; Customization: hooks a
;; function doing the customization. The function is the see
;; the example section below.) The following hooks lding mode is activated.
;; o `<major mode>-folding-hookjor
;; mode set to <major mode>. (e.g. When editing C the hook `c-mode-folding-hook' is called.)
;; o `fol Called when folding mode is loaded into Emacs.
;;
;; C it is used by outline-minor-mode. It is not likely that fe try to use folding and outline at the same time.
;;
;; Ho. The
;; variable `folding-default-keys-function' specifiing line to your
;; init file:
;;
;; (setq folding-default-keys-function
;; 'folding-bind-backward-compatible-keys)
;;
;; To define keys similar to the keys used by Outline mode, use:
;;
;; (setq folding-defaut-keys-function
;; 'folding-bind-outline-compati-keys)
;;
;; Customization: adding new major modes
;;
;; To add fold marks for a new major mode, use the function
;; `folding-add-to-marks-list'. The command also replaces
;; existing marks. An example:
;;
;; (folding-add-to-marks-list
;; 'c-mode "/* {{{ " "/* }}} */" " */" t)
;;
; Customization: ISearch
;;
;; If you don't like the extension folding.el applies to isearch,
;; set the variable `folding-isearch-install' to nil before
;; loading this pacndard
;; ones, you can do like this:
;;
;; (setqs-function
;; '(folding-bind-backward-compatible- "Folding setup."
;;
;; (folding-install) ;; jus;; ............................................... markers ...
;; ;; sh/perl/awk code
;;
;; (defvar f-marks-alist nil)
;;
;; (let* ((ptr (assq 'text-mode folding-mode-marks-alist)))
;; (setcdr ptr (list "# {{{" "# }}}")))
;;
;; ;; .....................rrent-entry)
;; (define-key folding-mode-prefix-map 'folding-whole-buffer))
;;
;; Example:;; (defun my-folding-load-hook ()
;; "Foldi; Change marks for 'text-mode'
;; (let* ((ptr (assqing-mode-marks-alist)))
;; (setcdr ptr (list "# {{xample: choosing different fold marks for mode
;;
;; Suppoerent fold marks for the
;; major mode: e.g. to alternate (defun my-folding-text-mode-setup (&optional use-cu (interactive
;; (list (y-or-n-p "Us; (let* ((ptr (assq major-mode folding-mode-marks- (when (eq major-mode 'text-mode)
;; (setq begin default-begin end default-end)))
;; (setcdr ptr (list begin end))
;; f these 3 is to be folded at any
;; one time, using a simpomment types, e.g., "unfold
;; everything then fold on \x";;
;; \O ... \endO
;; \L ... \endL
;; "Folding vars setup."
;; (let ((ptr (assq 'te;; (define-key folding-mode-prefix-map "C"
;; 'my-folding-marks-change)))
;;
;; ctive "P")
;; (let ((ptr (assq major-mode folding-mome major-mode))
;; (setq input
;; read-string "Latex \\end(X) Marker (default O): "
;; (setq input (upcase input))
;; (turnncat "\\" input) (concat "\\end" input)))
;; (tu ;; End of example
;;
;; Bugs: Lazy-shot.el conflict in in the minibuffer and XEmacs freezes.
;;
;; The strange phat I have this bug only under Solaris
;; 2.5 sparc (binar.6 x86. (XEmacs 20.4, folding 2.35). I will try to access
;; ;; the XEmacs people I you can reproduce it.
;;}}}
;;{{{ Documentation
;; Old documentation
;;
;; The following s written by Jamie Lokier for the release
;; of Folding V1t is included here for no particular reason:
;;
;; Emacs 1 frames, then move in
;; and out of folds in the buffer. Tnerally in order to
;; avoid some Emacs display "features"ome of it is specific to
;; certain versions of Emacs. By ;;
;; More known bugs
;;
;; *** Needs folding-fold-regionk out what happens when you
;; exit a fold with the file dat sometime.
;;
;; Future features
;;
;; *** I will add a earlier versions does not count line-numbers in the right
;; ve.
;;
;; *** Fold titles should be optionally allowed on invisible text-properties (I hope they are intended to
;; sible; it isn't implemented like that yet), it
;; will be ed text without affecting the
;; text of the buffer. At thrns for line-feeds in the buffer. This isn't such
;; a gooeven more text-properties, it may be possible to track
;; and out of folds, and have Folding mode
;; automatically e necessary to maintain a
;; sensible display. Because the dified (if
;; overlays are used to hide text), this is quiorward-char', `folding-goto-line' or
;; `folding-next-erromight make it possible to
;; avoid using narrowing. This m3cff7]
;; - Minor documentaton fixes.
;; - Add new `python-mode [jari 3.36-3.37 2006.1118]
;; - Jeremy Hankins <nowan An org> sent a patch, which
;; adds variable `folding-narrow-batch affects
;; mostly `folding-shift-in'. This makes it possader to the beginning for canonnical location.
;; Updated maid from bibtex-mode.
;; Changed bib-mode '#comment' => '%'. Clian
;; Bug#282388
;;
;; Sep 10 2004 21.3 [jari0]
;; - (folding-fold-region): caused to indent bottom fold
;; -mode. Disabled
;; running `indent-according-to-mode' while i; Bug reported by Uwe Brauer; oub A T mat dot ucm dot es
;; -whole buffer.
;; - Changed version scheme to date based YYYY.MMed unnecessary 'all rights reserved'.
;; - (folding-check-foldeter, which
;; - protected all email addresses by removing AT-si2.111-2.115]
;; - Merged in changes made by 2003-11-12 Adrian ; using different expansion macros for XEmacs and Emacs.
;; rg/xemacs-beta/199810/msg00039.html
;; - (folding-forward-char- 2.112 Renamed.
;; Was `folding-forward-char'.
;; (folding-ar-1): 2.112 Renamed.
;; Was `folding-backward-char'.
;; (fion with '_p' interactive spec.
;; (folding-backward-char-macolding-interactive-spec-p): 2.112 New.
;;
[...]
There's at least one error in the code in your .emacs, here:
; to enable folding mode
(load "folding" 'nomessage 'noerror)
(folding-mode-add-find-file-hook)t
That t is a syntax error as it stands. Might just be a type frpom cut and paste though.
On the error, Trey'd right, and in fact I think I know what the error probably is: somehow the trailing quote mark in the string
"Latest folding is available at http://cvs.xemacs.org/-xemacs-p
has gone missing. From the two of these issues, I suspect your source is corrupt.
It looks like your folding file /Users/Masi/.lisp/folding.el has a problem, we'd need to see the contents of that to determine the error. The reason I say so is that the stack trace goes through a call to load-with-code-conversion - which shows the folding.el file being loaded.
If you take a look at the latest version, found here (version 3.42), the line that begins
(defvar folding-package-url...
is properly formed. However, the stack trace in yours looks like there is some lisp code that somehow made it into the string. Namely the:
(or (boundp 'xemacs-logo)
Try downloading a fresh copy.