org--agenda-prefix-format %? does not work - emacs

Currently, I have my global TODO list shown as follows thanks to erikstokes:
(org-agenda-prefix-format " %i %?-12(concat \"[ \"(org-format-outline-path (list (nth 1 (org-get-outline-path)))) \" ]\") ")))
which outputs:
for org layout:
However, as you can see, for Task A, even though there is nothing in the project, it still shows up on the list.
describe-variable for org-agenda-prefix-format says :
If the first character after `%' is a question mark, the entire field
will only be included if the corresponding value applies to the current
entry. This is useful for fields which should have fixed width when
present, but zero width when absent.
So I feel like by using %?, [ ] shouldn't be there for Task A, yet it still shows up.

The problem is that the field is never empty: it will always contain at least the left and right square brackets plus the white space to bring it to a width of 12.
The solution is to write a function that returns either an empty string or the bracketed project and use that in the format:
(defun foo ()
(let ((x (nth 1 (org-get-outline-path))))
(if x
(concat "[ " (org-format-outline-path (list x)) " ]")
"")))
(setq org-agenda-prefix-format " %i %?-12(foo) "

Related

Checking user input in Racket

I am getting an input from a user for a tex-field% in racket which would look something like this:
open button a = fwd; button b = xxx; button s = xxx; close
I have verified that it does contain open and close at beginning and end respectively. But now i need to store each of the substrings based on the semicolons to check them for semicolons at the end, among other things. For example, in the example above it should store 3 substrings in a vector/list (whichever is easier). It would be stored as:
button a = fwd;
button b = xxx;
button s = xxx;
;input is the name of the string the user enters
(define vec (apply vector (string-split input)))
(define vecaslist(vector->list vec))
(define removedopen (cdr vecaslist))
(define withoutopenandclose (reverse(cdr(reverse removedopen))))
(define stringwithoutopen (string-replace input "open " ""))
(define stringtoderivate (string-replace stringwithoutopen " close" ""))
(define tempvec (apply vector (string-split stringtoderivate ";" #:trim? #f #:repeat? #t)))
Attempted to split it by semicolons and place in a vector, but it removes the semicolons. When i do print the length of the vector it correctly shows 3 though, but i would like to keep the semicolons for now.
You can use string-split with a regular expression separator, as follows:
(string-split input #rx"(open | close)|(?<=;).")
which will output the list:
'("button a = fwd;" "button b = xxx;" "button s = xxx;")
To break down the regular expression:
(exp) matches any sub-expression "exp". Hence, (open ) matches the sub-expression "open " in input. Similarly with ( close), matching " close".
(?<=exp) does a positive look-behind, matching if "exp" matches preceding.
. matches anything, such as whitespace, characters etc.
| matches either the expression that comes before it, or after it, trying left first.

How I can change column view (org-mode, agenda) - default settings

(setq org-agenda-custom-commands
'(
("1" "TODAY" agenda "" (
(org-agenda-ndays 1)
(org-agenda-use-time-grid nil)
(org-agenda-overriding-columns-format "%TODO %7EFFORT %PRIORITY %100ITEM 100%TAGS")
(org-agenda-view-columns-initially t)))
("2" "TODO" todo "TODO"(
(org-agenda-files '("/Users/inbox.org"))
(todo "NEXT")))
("3" "DONE" todo "DONE")...
In the first filter (1 = TODAY), I have following function:
org-agenda-overriding-columns-format...
How can I add this function for all my filters (2, 3) and create this as default?
Set the variable in your .emacs (or other initialization file):
(setq org-agenda-overriding-columns-format "%TODO %7EFFORT %PRIORITY %100ITEM 100%TAGS")
BTW, org-agenda-overriding-columns-format is a variable, not a function.
You can set the column widths by customizing the org-columns-default-format variable. So:
M-x customize variable org-columns-default-format
There, you can change the number in front of each column name to the character width you want. For example, if you want the ITEM column to be 50 characters wide, change %25ITEM to %50ITEM.
And if a column doesn't have a numeric value after the percent sign, you can add one.
Hope that helps.

Emacs repeat until a given column?

When adding a divider in code I can easily repeat a '=' N times using
C-<N> =
where N is the number of equal signs to insert.
Is there a similarly quick command that would insert a character repeatedly up to a given column number? So I could execute
<magic command>-<N> =
and get a line of equal signs from the present cursor position to column N?
I don't know of anything built in that can do that, but you could bind the function below to a key sequence of your choice:
(defun repeat-char-to-column (column character)
"Insert copies of CHARACTER on the current line until column COLUMN.
Interactively, prompt for COLUMN and CHARACTER. If the current column is
equal to or greater than COLUMN, do nothing."
(interactive "nRepeat to column: \ncCharacter to repeat: \n")
(let ((cur (current-column)))
(if (< cur column)
(insert (make-string (- column cur) character)))))

When do variables output properly in skeletons functions?

I'm trying to write a skeleton-function to output expressions in a loop. Out of a loop I can do,
(define-skeleton test
""
> "a")
When I evaluate this function it outputs "a" into the working buffer as desired. However, I'm having issues when inserting this into a loop. I now have,
(define-skeleton test
"A test skeleton"
(let ((i 1))
(while (< i 5)
>"a"
(setq i (1+ i)))))
I would expect this to output "aaaaa". However, instead nothing is outputted into the working buffer in this case. What is happening when I insert the loop?
The > somestring skeleton dsl does not work inside lisp forms.
You can however concatenate the string inside a loop:
(define-skeleton barbaz
""
""
(let ((s ""))
(dotimes (i 5)
(setq s (concat s "a")))
s)
)
My understanding is that code such as
> "a"
only works at the first nesting level inside a skeleton.
[EDIT] Regarding your question
What is happening when I insert the loop?
The return value of the let form (that is, the return value of the while form)is inserted. I do not know why it does not raise an error when evaluating > "a", but the return value of a while form is nil, so nothing is inserted.
I do agree that there's not much point using define-skeleton if you're going to need an (insert function within the skeleton.
This is also a rather trivial example to be using define-skeleton.
That said, they are often easier to read than a defun and useful when you want to create a function that inserts text (and optionally, takes input).
For example you may wish to have a different character repeated a set no. of times... Below, str refers to the argument supplied with the function (usually a string) and v1, v2 are the default names for local variables in a skeleton. Thus:
(define-skeleton s2 ""
nil ; don't prompt for value of 'str'
'(set 'v1 (make-string 5 (string-to-char str)))
\n v1 \n \n)
Below, calling the function leads to a newline, the string, then leaves the cursor at the position indicated by the square brackets [].
(s2 "a")
aaaaa
[]

What's the corresponding standard function of atoi in clisp?

In visual lisp, you can use (atoi "123") to convert "123" to 123. It seems there is no "atoi" like function in clisp ?
any suggestion is appreciated !
Now i want to convert '(1 2 3 20 30) to "1 2 3 20 30", then what's the best way to do it ?
parse-interger can convert string to integer, and how to convert integer to string ? Do i need to use format function ?
(map 'list #'(lambda (x) (format nil "~D" x)) '(1 2 3)) => ("1" "2" "3")
But i donot know how to cnovert it to "1 2 3" as haskell does:
concat $ intersperse " " ["1","2","3","4","5"] => "1 2 3 4 5"
Sincerely!
In Common Lisp, you can use the read-from-string function for this purpose:
> (read-from-string "123")
123 ;
3
As you can see, the primary return value is the object read, which in this case happens to be an integer. The second value—the position—is harder to explain, but here it indicates the next would-be character in the string that would need to be read next on a subsequent call to a reading function consuming the same input.
Note that read-from-string is obviously not tailored just for reading integers. For that, you can turn to the parse-integer function. Its interface is similar to read-from-string:
> (parse-integer "123")
123 ;
3
Given that you were asking for an analogue to atoi, the parse-integer function is the more appropriate choice.
Addressing the second part of your question, post-editing, you can interleave (or "intersperse") a string with the format function. This example hard-codes a single space character as the separating string, using the format iteration control directives ~{ (start), ~} (end), and ~^ (terminate if remaining input is empty):
> (format nil "Interleaved: ~{~S~^ ~}." '(1 2 3))
"Interleaved: 1 2 3."
Loosely translated, the format string says,
For each item in the input list (~{), print the item by its normal conversion (~S). If no items remain, stop the iteration (~^). Otherwise, print a space, and then repeat the process with the next item (~}).
If you want to avoid hard-coding the single space there, and accept the separator string as a separately-supplied value, there are a few ways to do that. It's not clear whether you require that much flexibility here.