Simple minor mode to hold easy-menu [closed] - emacs

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to have a menu which I would call when I'll need it. I think that minor mode -- is the way to go. So I've written a minor mode, which only defines keymap and easy-menu:
;; keymap:
(defvar bk-mdanalysis-mode-map
(let ((map (make-sparse-keymap)))
map)
"Keymap for bk-mdanalysis minor mode")
;; menu:
(easy-menu-define mda bk-mdanalysis-mode-map "bk-mdanalysis-mode menu"
'("BK-MDA"
["Test" (lambda () (interactive) (insert "test!")) t]
))
(define-minor-mode bk-mdanalysis-mode
nil nil nil
bk-mdanalysis-mode-map)
(provide 'bk-mdanalysis-mode)
For some reason it doesn't work. What is wrong?
Edit:
Wait a minute -- it works!
Should I delete it now -- or what?

You placed bk-mdanalysis-mode-map as 5th argument to define-minor-mode whereas it should be the 4th argument. Lucky for you define-minor-mode will use it by default anyway, so it still works and this 5th argument will just be ignored.

Related

Adapting UCI lisp function with a loop to common lisp [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm currently trying to recreate an old program written in UCI Lisp using Common lisp but I'm not very fluent with Lisp.
The original function is:
(DE SETROLE (ROLE FILLER CD)
(CONS (HEADER:CD CD)
(APPEND (FOR (PAIR IN (ROLES:CD CD))
(WHEN (NOT (EQUAL (ROLE:PAIR PAIR) ROLE)))
(SAVE PAIR))
(LIST (LIST ROLE FILLER]
Here's my common lisp interpretation:
(defun setrole (role filler cd)
(cons (header/cd cd)
(append (loop for pair in (roles/cd cd)
do (when (not (equal (role/pair pair) role))
(save pair)))
(list (list role filler)))))
This is the error that comes up:
*** - EVAL: variable WHEN has no value
My initial thinking is that there is no equivalent 'save' function. The description of the function is:
SETROLE Makes a new CD form with (ROLE FILLER) added or replacing the old (ROLE ...) pair.
Kindly help, I'm stumped
I found the bug. There was a loose 'when' in the wild below the code.

How to exchange words in emacs(by replace them with each other one) [duplicate]

This question already has answers here:
How can I swap or replace multiple strings in code at the same time?
(5 answers)
Closed 8 years ago.
Say I have some text like:
First one is good, so I used first one.Second one is bad, so I drop it.
I want to switch the 'first' and 'second',and like replace-string,leave the capital to the same case as original word.
Is there any built-in functions to handle this situations?
Edit:
Let me explain the problem further.If I use usual replace-string twice,will some times cause unwanted results.In the example above, If using replace-string first RET second RET, then replace-string second RET first RET,it will out put: First one is good. so I used first one.First one is bad, so I drop it. It also a problem in some case like "clientFolder=>serverFolder and server=> client"
#huaiyuan answered the same question here:
How can I swap or replace multiple strings in code at the same time?
His code allows you to enter arbitrary list of pairs to do parallel replacement.
Incidently, if you want to read some cool lisp code, click on #huaiyuan and read his answers.
Here's a great trick courtesy of Mickey's Mastering Emacs blog (see http://www.masteringemacs.org/articles/2013/01/25/evaluating-lisp-forms-regular-expressions/ under the heading "Swapping Elements")
C-M-% \(first\)\|second RET \,(if \1 "second" "first") RET
Edit: and here's an elisp version of that:
(defun my-swap-text (a b)
"Swap two pieces of text wherever they appear, using `query-replace-regexp'."
(interactive "sSwap: \nswith: ")
(let ((use-region (and transient-mark-mode mark-active)))
(query-replace-regexp
(rx (or (group (eval a)) (eval b)))
(quote (replace-eval-replacement replace-quote (if (match-string 1) b a)))
nil
(when use-region (region-beginning))
(when use-region (region-end)))))
did you google search this at all?
http://kb.iu.edu/data/abdp.html

LISP list of expressions [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a list of expressions that I want to evaluate in order inside a macro and return the value of the last one. I've tried this, but the compiler doesn't like it:
(defmacro foo lst-of-exprs
',#lst-of-exprs)
and
(defmacro foo lst-of-exprs
'(progn ,#(lst-of-exprs))
Is there a way to do this without using a do loop?
You want
(defmacro foo lst-of-exprs
`(progn ,#lst-of-exprs))
although really this is just defining a synonym for progn itself.

Keeping track of global variables in recursive functions [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I've been struggling with this question for the past few hours, scoured the internet for help, and I still can't seem to figure it out.
The question is simple:
Write a recursive program (in lisp) that takes a list and returns the number of 'a atoms in the list.
From the research I've done, it seems like LISP has an implicit counter in it, where if you just do (+ 1) it will keep track? Is this off?
Please help, I'm pretty frustrated...
The idea here is not to use a global variable, but instead to keep the count "in the stack".
Here's a Scheme solution. I'm sure you'll be able to convert this to whatever Lisp dialect you're using:
(define (count-a lst)
(cond ((null? lst) 0)
((eq? (car lst) 'a) (+ (count-a (cdr lst)) 1))
(else (count-a (cdr lst)))))
If that's not DRY enough for you, here's a more condensed version:
(define (count-a lst)
(if (null? lst) 0
(+ (count-a (cdr lst)) (if (eq? (car lst) 'a) 1 0))))
You just need to have a counter carry along in a parameter. I haven't used LISP in forever but just a simple (+ counterName 1) as a parameter should keep track. Don't forget to throw it a starting value though.

How to display indentation guides in Emacs? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm trying to switch to Emacs as my primary source-code editor. I really miss one thing (common in even much simpler editors) - indentation guides (unobtrusive vertical lines which show the indentation level). Is Emacs able to display them?
I've made a function highlight-indentation for this purpose, code is on github.
When invoking highlight-indentation without a prefix argument the current indentation level is naively guessed from major mode (python, ruby and languages based on cc-mode). Only works for space indentations. Customize highlight-indent-face to change appearance of indentation lines.
Examples (ruby, python):
I also frequently use this snippet that folds all code on an indentation level greater than the current line. It's a great way of getting a quick overview of the outline.
(defun aj-toggle-fold ()
"Toggle fold all lines larger than indentation on current line"
(interactive)
(let ((col 1))
(save-excursion
(back-to-indentation)
(setq col (+ 1 (current-column)))
(set-selective-display
(if selective-display nil (or col 1))))))
(global-set-key [(M C i)] 'aj-toggle-fold)
There now is a mode called highlight-indent-guides which seems to work quite well.
to my knowledge nobody has implemented indentation guides for Emacs so far. The closest thing you can get are visualization of TABs with the whitespace package, see Show tabs with a different character (Emacs).
Suppose you could bend ColumnMarker to your needs but it will highlight a column
not givin you a single pixel.
I indent with 8 spaces so i have never thought about it ;P