I see this in the lecture slide
> (+ 10 (-< 1 2 3))
11
> (next)
12
> (next)
13
> (next)
'done
But when I tried it my own in DrRacket, it came up with an error
> (+ 10 (-< 1 2 3))
. . -<: undefined;
cannot reference an identifier before its definition
>
The slide didn't indicate any requirement. I also google "racket -<: undefined", but seems google can't find any result relate to the symbol -<. How can I fix it?
Based on the link to the slides that you posted, it appears that the -< form is defined as a macro (using syntax-rules) on slide 19/48. After you add that macro definition to your program, you should be able to use the -< form.
Related
I am trying to select the third window (I have opened 6 in my frame) in Emacs.
The problem is that this:
(select-window 3)
doesn't work.
It throws this error in debugger:
(wrong-type-argument window-live-p 3)
How to make it work?
select-window takes a window object as argument, not a number. The function window-list gives you a list of window objects in the current frame. You can select one of them to pass to select-window, e.g.
(select-window (nth 2 (window-list)))
will select the window that is the third[1] element of the list that window-list returns.
Do C-h f nth and C-h f window-list for more information on these functions.
EDIT: in response to the comment...
What I know about Windows (which is not much), I've learned by reading parts of the Windows chapter in the Emacs Lisp Reference manual.
Do NOT expect the window number to correspond to anything that you think as "first" or "second" or ...
When you destroy windows and then create new ones, the numbers are going to change unpredictably (at least AFAIK), e.g. I had three windows with numbers 51, 83 and 99. I destroyed window #99 and created a new one: now window-list tells me I have windows with numbers 51, 105 and 83 in that order. I believe (but I may be wrong) that Emacs uses the list returned by window-list in order to implement other-window (C-x o), so the order of the list that window-list returns depends on what your selected window is currently: that' always the first element of the list, so the window you'll select with C-x o is the second element of the current list, but when you get there and do ESC ESC : (window-list), the returned list will have changed - it will be rotated so that where you are is the first element and where you came from is now the last element. See Cyclic Ordering of Windows in the Emacs Lisp Reference manual.
You are correct that the upper case WINDOW in the function description is a hint of its type. For typographic conventions, see the section Conventions in the Emacs Lisp Reference manual and in particular, the subsection A Sample Function Description.
[1] Note that list elements are indexed from 0.
So I keep a phone log for work in org-mode. A new call comes in and I start a capture template which marks it as a TODO. When that item is completed, I marked it as DONE. I then add a tag if that phone call is related to a different department, :SALES: :ACCOUNTING: :SERVICE:
Can you think of a way to keep a running total of how many calls are tagged for the other departments? Ideally, it would be in the same Org file as a table.
Basically, I am trying to justify that our company now needs a receptionist. Any ideas?
The following example is my interpretation of your question. It uses org-map-entries to search the buffer for tags, for each tag in a given list.
* DONE call 1 :sales:
* DONE call 2 :sales:
* DONE call 3 :accounting:
* DONE call 4 :sales:
* DONE call 5 :sales:
* Summary
#+begin_src elisp :export results
(mapcar (lambda (tag)
(list tag (length (org-map-entries t tag nil))))
'("accounting" "sales"))
#+end_src
#+RESULTS:
| accounting | 1 |
| sales | 4 |
You can tweak the match strings for better filtering.
Say you have a tree of the following form:
* Top
** Item A
*** Lower
** Item B
** Item C
What I would like to do is to be able to make a region containing Item A and Item B, and have a command run to change it into this:
* Top
**
*** Item A
**** Lower
*** Item B
** Item C
With the cursor at the blank item. I am wondering if something similar is already written into org-mode. If not, I can write it myself, but in that case I am wondering how I should loop through the lines in my region to shift them, avoiding items which are on a lower level than my starting one.
A naive first try
Starting with the outline
* Top
** Item A
*** Lower
** Item B
** Item C
If I place my cursor after Top and press Alt + Return (org-insert-heading) followed by Alt + Shift + right (org-demote-subtree) I get the structure
* Top
**
*** Item A
**** Lower
*** Item B
*** Item C
Unfortunately this demotes Item C, which you don't seem to want. However, you can just navigate to this item and press Alt + Shift + left. However, I imagine that this is a simplified example and want a more powerful method which doesn't involve moving around the file too much. Can we do better?
Transient mark mode
Reading through structure editing in the Org mode manual I found the note
When there is an active region (Transient Mark mode), promotion and demotion work on all headlines in the region. To select a region of headlines, it is best to place both point and mark at the beginning of a line, mark at the beginning of the first headline, and point at the line just after the last headline to change.
So perhaps this gives us a way forward. However, I haven't been able to do anything sensible with this information. Hopefully someone else can step and and show us how it is done.
Narrowing to a region
One other way we can move more is to "narrow" the buffer to only the region we want to work on.
Select the lines * Top, ** Item B in full and everything in between (with your mouse or by, for example, using Ctrl + Space and Ctrl + c + Ctrl + n (outline-next-visible-heading) a few times). We can now focus our attention on only this highlighted (or marked) region by "narrowing" the buffer to only this region, to the exclusion of all other text in the buffer (we won't delete the text, even though it will look that way, we'll just hide it for a bit. We narrow to the region by using Ctrl + x + n + n (narrow-to-region) (note the helpful message that appears if you haven't explicitly enabled this feature). We can always get back to the full buffer by using Ctrl + x + n + w (widen).
In our narrowed buffer we can now only see:
* Top
** Item A
*** Lower
** Item B
If we now repeat the steps from our naive try (see above) and then returning to the full (widened) buffer we see that we have the outline:
* Top
**
*** Item A
**** Lower
*** Item B
** Item C
which is the final result we were after! My apologise if this is an unnecessarily long answer. I learnt a lot researching it and wanted to document it all here.
Based off Chris's answer, I came up with the following code:
(defun org-file-region (start end)
"Moves the lines in region to be underneath a new header"
(interactive "r")
(extend-region-to-lines start end)
(narrow-to-region (save-excursion (goto-char start)
(line-beginning-position))
(save-excursion (goto-char end)
(line-end-position)))
(org-do-demote)
(org-insert-heading)
(setq mark-active nil)
(org-do-promote)
(setq mark-active t)
(widen))
Note that only org-do-demote will operate on the region; the other demotion functions do not.
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)
)
What does this do?
(add-hook 'compilation-mode-hook #'my-setup-compile-mode)
...and is it different than
(add-hook 'compilation-mode-hook 'my-setup-compile-mode)
There is no difference:
(eq 'my-add #'my-add)
yields t
The # can be used in front of a lambda expression indicating to the byte-compiler that the following expression can be byte compiled, see the docs for Anonymous Functions. But there's nothing to compile in the case of a symbol.
In general, it is used in the printed representation along with the left angle bracket (<) to indicate that the object printed is a description (but cannot be read). For example:
#<buffer foo.txt>
It is also used in constructs by the reader to represent circular structures. See the docs for Read Syntax for Circular Objects.
And then you have its use for denoting the base for integers, e.g. #x2c -> 44.
Plus more I'm sure.
The should-be-comprehensive list can be found at the top of the Emacs lisp reference index.
Edit: Or even more conveniently, from within Emacs itself:
M-x info RET (open the info browser)
d m elisp RET (open the elisp manual)
I # RET (list the entries for # in the index)
I found this question while searching for what the hash meant in something I found while hacking mode-line-format:
#("-%-" 0 3
(help-echo "Display as tooltip when mouse hovers or with display-local-help."))
which is a format used for text properties in strings where:
"-%-", text to be propertized: one dash and a %-construct that results in "dashes sufficient to fill the remainder of the mode line", resulting in the famous Emacs ------.
0, the first character upon which the text properties apply.
3, the last character upon which the text properties apply, i.e. the entire "-%-".
(help-echo "..."), a property and a string as its argument.
This can be created with the propertize function:
(propertize "Hover over me!" 'help-echo '"congratulations!")
would be the same as #("Hover over me!" 0 14 (help-echo "Congratulations!")):
If you're using font lock mode, using the buffer-substring command might produce something like this:
(buffer-substring 1 28) ; First 27 characters in the current buffer
⇒ #(";; This buffer is for notes"
0 3
(fontified t face font-lock-comment-delimiter-face)
3 27
(fontified t face font-lock-comment-face))
So you could create something like: