I have a probably rather simply to solve (Auto-)LISP problem to solve. I have a script which works fine basically, but it requires me to manually select objects (texts in my case) and hit enter.
I want to select all text objects from all layers, and apply the same TCIRCLE operation on all of them. This command should later be applied with a script to automate imports, that's why there must be no manual interaction.
This is the working basic script which requires manual selection:
(defun c:MyTcircle ( / ss)
(if (not bns_tcircle) (load "acettxt.lsp"))
(if (setq ss (ssget '((0 . "TEXT,MTEXT,ATTDEF"))))
(bns_tcircle ss "Variable" "Rectangles" "" 0.35)
)
(princ)
)
I've tried to create a filter collection with setq sset for the same type filters as above. But it doesn't do anything (no error but also no changes). So either my collection is empty, or the command isn't called right.
I'm new to AutoLisp, what am I missing that it doesn't work as expected on the filtered items?
You need to add a filter to your selection set. Simply adding a comma between the different entity types just gives you a malformed entity.
Take a look here for some information to get you started: http://www.afralisp.net/autolisp/tutorials/selection-set-filters.php
Related
I'm using clojure-mode and clojure.test/with-test, which looks like this:
(with-test
(def... some expression defining a var)
;; comment for a test
(is (= 0 (- 1 1)))
(is ...))
Where the expressions following the first one in (with-test ...) are test cases for the first form. This is useful since it keeps tests close to their relevant code.
However, the list of test cases may be pretty long, obscuring the rest of the "real" code. I would love to have some way of hiding all of the test code in a buffer. Something like outline/org-mode's folding abilities:
(with-test
(def some expression defining a var)
...)
Or even
(def some expression defining a var)
with some kind of marker to show there are hidden test cases.
The tricky part about this is that the (def...) form that I want to focus on is inside the (with-test ...) form that I want to hide.
I've looked around and as far as I can see I won't be able to make this work with outline-mode or hideshow-mode. I'm assuming I need some folding library that is expression-aware to get something like this to work. Does something like this already exist, am I thinking about this the wrong way, do you have any tips?
Update
I was able to make it work with hideshow. See the hs-hide-all-clojure-tests in my emacs config repo
I believe, that you can use the HideShow package for this task, but you'll need to add some configuration so it will hide only tests...
This has got to be a stupid simple question, but I haven't been able to find an answer despite searching Google multiple times in multiple ways, and digging through the Calc documentation.
GIVEN an instance of Emacs, with Calc running, and having performed multiple calculations including storing variables and equations, some of which may have come from the "~/.emacs.d/calc.el" file,
HOW do you return Calc to a pristine state without restarting Emacs?
Pristine: Nothing on the stack. Nothing in the trail. No stored variables or equations. Etc.
M-x calc-reset, which is also bound to C-x * 0, is what you need. From the info manual:
The C-x * 0' command ('calc-reset'; that's 'C-x *' followed by a
zero) resets the Calculator to its initial state. This clears the
stack, resets all the modes to their initial values (the values that
were saved withm m' (calc-save-modes')), clears the caches (*note
Caches::), and so on. (It does _not_ erase the values of any
variables.) With an argument of 0, Calc will be reset to its default
state; namely, the modes will be given their default values. With a
positive prefix argument,C-x * 0' preserves the contents of the stack
but resets everything else to its initial state; with a negative prefix
argument, `C-x * 0' preserves the contents of the stack but resets
everything else to its default state.
EDIT: Oops. Even that doesn't clear variables. I'm not sure if there is a straightforward way to get all the way back to pristine :(
EDIT 2: It looks like Calc stores all variables, including 'built-ins' like pi and e, as global variables with the prefix 'var-'. As far as I can tell, it doesn't keep track of which variables were set by the mode (like pi), and which were set by users. Furthermore, the default user variables are stored as var-q0, var-q1 etc. So in order to clear out all the variables, you'd need to compile a list of variables and states present at startup, erase everything not in that list, and then restore the original values of the variables in that list. That's certainly possible, but a little tedious.
Edit 3: Here's my attempt. I took another look at calc-mode, and at start up it defines the variables I've added to my-calc-builtin-vars below. The second line will remove all variables in Emacs that start with the prefix 'var-' and are not in this list. This will include any variables defined by you, or in another package. So let's hope no-one else uses the prefix 'var-'. And it will not reset the value of the built-in variables, so if you have redefined pi to 3, it will remain 3.
(setq my-calc-builtin-vars
'("var-nan" "var-uinf" "var-sym" "var-lines" "var-Modes"
"var-EvalRules" "var-inf" "var-phi" "var-pi" "var-gamma" "var-π"
"var-φ" "var-γ" "var-spec" "var-e" "var-i"))
(defun really-reset-calc ()
(interactive)
(calc-reset nil)
(mapc #'(lambda (el) (unintern el))
(remove nil (mapcar
#'(lambda (el) (unless (member el my-calc-builtin-vars) el))
(all-completions "var-" obarray)))))
UPDATE: August 6, 2016
Current built-in vars list:
(setq my-calc-builtin-vars
'("var-CommuteRules" "var-Decls" "var-DistribRules" "var-EvalRules"
"var-FactorRules" "var-FitRules" "var-Holidays" "var-IntegAfterRules"
"var-IntegLimit" "var-InvertRules" "var-JumpRules" "var-MergeRules"
"var-Modes" "var-NegateRules" "var-e" "var-gamma" "var-i" "var-phi"
"var-pi" "var-γ" "var-π" "var-φ"))
M-# 0
That should be all you need to do.
Let's say I want to create a new document, and cycle quickly through a list.
If it's only for one "word", I think there should be a general way to do this.
For instance:
"blue orange red yellow black white"
Does anyone know a way how to cycle through those items when I create:
\begin{orange}
... and I want to press a key to cycle through this list, replacing orange with the next item on the list (doing this procedure in the opposite direction wouldn't be hard then)?
I tried many different ideas with macro's (placing the list on the top of the document, and doing a whole bunch of i-searches), but that doesn't cut it.
I'd be willing to put the list in an elisp file, though I have no clue how to use that variable from elisp in, let's say, a LaTeX document (.tex).
Well, this might be possible, but depends on how much effort you are willing to put into writing eLisp code to make it work. It's not possible by just some configuration option. I would be looking into extending autocomplete by adding new sources to it, something like:
(defvar tex-tag-ac-sources
'((init . tex-tag-ac-init)
(requires . 0)
(candidates . tex-tag-ac-candidates)
(document . tex-tag-ac-documentation)
(match . tex-tag-completion-filter)
(prefix . tex-tag-ac-prefix-matcher)
(symbol . "s"))
"The source generator for autocompletion needed for interaction
with auto-complete")
Where tex-tag-ac-candidates, tex-tag-ac-documentation, tex-tag-completion-filter and tex-tag-ac-prefix-matcher are function that do autocompletion. I.e. init function is called once when the autocompletion process starts for a specified prefix. It's called w/o arguments. The candidates is the function that is responsible for showing the filtered list of candidates, it's called w/o arguments, you would filter the candidates in the filter function, it is called with the prefix collected so far and the list of candidates so far. Lastly, the matcher function is invoked on the text of the file to see if the completion is needed at point. So, if it returns t, the init is called, and then loops through filter-candidates as you type.
While this is a bit involved... you'd definitely have a completion for anything you want. Obviously, if those functions in source are defined by you, then, if you wanted to, you could read completion arguments dynamically or have them generated dynamically in some way.
Ah, you would add the sources to autocomplete by something like:
(auto-complete (list tex-tag-ac-sources))
if doing it on per call basis, or
(setq ac-sources (list tex-tag-ac-sources <other sources>))
You can find more info here: http://cx4a.org/software/auto-complete/manual.html#Using_Source
EDIT: I translated the macro into a function.
Here is a way I did it. I created a file called "list.list" where my "lists" are saved. I saved the LaTeX templates for Beamer in there. I inserted them like this:
Antibes Bergen Berkeley Berlin ..... Antibes
Note that you should always put the first entry in twice to allow it to loop.
Here is the code:
(defun cycle-list-word ()
(interactive)
(right-word)
(backward-kill-word 1)
(find-file "/emacs-24.1/list.list")
(search-forward (substring-no-properties (car kill-ring)) nil t)
(right-word)
(backward-kill-word 1)
(bury-buffer)
(yank)
)
The documentation of org-agenda-sorting-strategy is quite vague when describing the two following sorting strategy. It specifies only how the tags are ordered between done and not done, but does not say anything about how the tags are ordered inside both classes:
todo-state-up Sort by todo state, tasks that are done last.
todo-state-down Sort by todo state, tasks that are done first.
If I list all tasks using a simple agenda command as the following
("z" "TEST" tags-todo ""
(
(org-agenda-sorting-strategy '(todo-state-up)) ;; Sort by todo state, tasks that are done last.
)
)
the (todo) tasks are displayed in the order MAYB TODO NEXT ACTF PAUS WAIT, which does not correspond either to the alphabetical order, neither to the order in my org-todo-keywords:
(sequence "ACTF(a!)" "PAUS(p#)" "WAIT(w#)" "NEXT(n!)" "MAYB(m!)" "TODO(t!)"
"|"
"DONE(d#)" "CANC(c#)"
)
(sequence "KNOW(k#/!)" )
I will get around and program my own org-agenda-cmp-user-defined function to order according to the position of the todo-keyword in org-todo-keywords, but I am surprised that todo-state-up does not already corresponds to this (and I am not feel proficient enough in LISP to dive in the code of org-mode yet).
(I am using Org-mode version 7.7 (release_7.7.615.g02c26.dirty) on GNU Emacs 23.3.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.22.0) of 2011-04-01)
Actually, after restarting org-mode with the new value of org-todo-keywords, it turns out that todo-state-up does use the order of org-todo-keywords.
So I have my display of tasks ordered by todo-keywords now, which really simplifies the writing of agenda shortcuts, and tremendously speed-up their execution (one single instruction as opposed to one per keyword).
Yay!
I ran into this exact same confusion, and restarting still didn't fix the problem. What I realized eventually was that I had TODO cycling order further customized using #+SEQ_TODO:, which was overriding the order of my global org-todo-keywords variable.
I have a HTML page, with html-mode enabled. I call function sgml-validate to check for any markup errors. It's based on compilation-mode. I want to remove some warnings from the compilation output, so I wrote a function and hooked it to compilation-filter-hook (this variable is not documented, but compilation-filter invokes it). Everything works. My problem is that how can I ensure my filter function only gets called when I started the compilation process on a HTML page (via sgml-validate)?
I see two methods, but none of them worked:
First, I can check the value of major-mode. But it always returns compilation-mode, since that is enabled on the *compilation* buffer. (I found a filter function in the source code of grep+, and they did check the value of major-mode. I can't figure out how can it work correctly.)
The other idea was than to only hook my filter function to the HTML file's buffer, but for similar reasons it couldn't work as the output of compilation process goes to a seperate buffer.
It sounds like you can advise smgl-validate so that it performs the filtering before it performs all it's other operations. For example:
(defadvice sgml-validate (around fix-filtering command activate)
(let ((return-value ad-do-it))
(filter-function return-value))))
Meanwhile, I found that compilation-start accepts an optional argument mode, which will be the major mode for the compilation buffer. So I can create a major mode derived from compilation-mode, and define there my filter function now hooked to the proper buffer.
The only problem is now that sgml-validate does not allow me to set the mode argument on compilation-start, but that's another question.
(I don't consider this the ultimate solution, of course.)