elisp dynamically generate string for keyword [duplicate] - emacs

This question already has an answer here:
Org Mode: Symbol's function definition is void: \,
(1 answer)
Closed 2 years ago.
I am a elisp noob and need some help for a custom agenda in org-mode. I need an agenda view that filters the todo entries based on a scheduled or deadline timestamp. I want to see all the todos due in the next 60s. I have working code with hardcoded timestamp, but I need the timestamp to be dynamic (based on the current date/time).
This code is working (fixed date/times):
(setq org-agenda-custom-commands
'(("P" "Notify List"
((org-ql-block
'(and (not (done))
(planning
:from
"2021-02-02 11:00"
:to
"2021-02-02 14:00"
)
)
))
)
))
But this code seems to just ignore the from and to keywords and displays all tasks with a scheduled or deadline date:
(setq org-agenda-custom-commands
'(("P" "Notify List"
((org-ql-block
'(and (not (done))
(planning
:from
(format-time-string "%Y-%m-%d %H:%M")
:to
(format-time-string "%Y-%m-%d %H:%M" (time-add (current-time) (seconds-to-time 60)))
)
)
))
)
))
Can someone help me out why the functions are not working. I tried with many different functions, that create a timestamp, used the timestamp, converted it to string. Nothing worked.
Thanks in advance.
Cheers

NickD presented the solution. Here is the final code, that is working for me. Thanks a lot NickD :)
(setq org-agenda-custom-commands
'(("P" "Notify List"
((org-ql-block
`(and (not (done))
(planning
:from
,(format-time-string "%Y-%m-%d %H:%M")
:to
,(format-time-string "%Y-%m-%d %H:%M" (org-time-add (org-current-time) (seconds-to-time 600)))
)
)
))
)
))

Related

emacs automatically highlight *E *F etc and highlight to EOL

I am trying to build my major mode for syntax highlighting log files from a certain tool flow.
and I've been using this excellent guide to get started
http://ergoemacs.org/emacs/elisp_syntax_coloring.html
but I would like to highlight "*W", "*E" and "*F"
but I cannot get that to work
here are my font-lock keywords
(setq mylog-font-lock-keywords
(let* (
;; define several category of keywords
(x-warnings '("UVM_ERROR" "UVM_FATAL" "^.*E" "F"))
(x-keywords '("UVM_INFO" "NOTE" "Note"))
(x-types '("UVM_WARNING" "*W," "xmsim"))
(x-constants '("ACTIVE" "AGENT" "ALL_SIDES" "ATTACH_BACK"))
(x-events '("at_rot_target" "at_target" "attach"))
(x-functions '("llAbs" "llAcos" "llAddToLandBanList" "llAddToLandPassList"))
;; generate regex string for each category of keywords
(x-keywords-regexp (regexp-opt x-keywords 'words))
(x-types-regexp (regexp-opt x-types 'words))
(x-constants-regexp (regexp-opt x-constants 'words))
(x-events-regexp (regexp-opt x-events 'words))
(x-functions-regexp (regexp-opt x-functions 'words))
(x-warnings-regexp (regexp-opt x-warnings 'words))
)
`(
(,x-types-regexp . font-lock-type-face)
(,x-constants-regexp . font-lock-constant-face)
(,x-events-regexp . font-lock-builtin-face)
(,x-functions-regexp . font-lock-function-name-face)
(,x-keywords-regexp . font-lock-keyword-face)
(,x-warnings-regexp . font-lock-warning-face)
;; note: order above matters, because once colored, that part won't change.
;; in general, put longer words first
)))
;;;###autoload
(define-derived-mode mylog-mode verilog-mode "log mode"
"Major mode for editing LOG FILES…"
;; code for syntax highlighting
(setq font-lock-defaults '((mylog-font-lock-keywords))))
(set-face-foreground 'font-lock-type-face "yellow")
;; add the mode to the `features' list
(provide 'mylog-mode)
as you can see I've tried a few things with out success.. any other words are highlighted correctly?
as a final touch I would like to for all occurenses of WARNING or ERROR I would like to highlight the entire line until EOL.
I have found some examples but none that show how to highlight until EOL in a major mode lisp file
This is an example (taken from my init.el). Hope it help.
(font-lock-add-keywords nil
'( ; high-light full line ending with "E" or "FATAL"
("^.*\\(E\\|FATAL\\)$" . 'font-lock-function-name-face)
; high-light full line beginning with '*E' '*F' '*W'
("^\\*[EFW]\\b.*$" . 'font-lock-comment-face)
; high-light only ending part of the lines which contain "F"
("\\b\\w*F$" . 'font-lock-function-name-face)
; high-light from "UVM" to end of line
("\\bUVM.*$" . 'font-lock-function-name-face)
; high-light only words that end with "G"
("\\b\\w*G\\b" . 'font-lock-function-name-face)
; bold things between 2 **, like **bold**
("\\*\\*.+?\\*\\*" . 'bold)))

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.

switch between printing configurations in emacs

The default printing in emacs is to print one page per paper with some margins.
I have this function that changes the margins and sets printing to two pages per paper "most numbers are to maximize printing space:
(defun ps-two-per-page ()
(interactive)
(require 'ps-print)
(setq ps-n-up-printing 2
ps-n-up-border-p nil
ps-paper-type 'letter
ps-font-size (quote (8 . 11))
ps-top-margin -20
ps-bottom-margin -35
ps-left-margin 18
ps-right-margin 18
ps-n-up-margin 1
ps-inter-column 1
)
'ps-two-per-page)
Once the function executes I will no longer able to go back to the default printing configuration.
How is it possible for me to go back to print using default configuration "as if I did not execute the above command"?
Also, is there way to bind the printing commands in emacs under the "file" drop down menu.
Meaning, I would like to bind "Postscript Print Buffer" to be print using the default configuration, and "Postscript Print Buffer (B+W)" to follow the configuration I have in the above command ps-two-per-page.
WRT to first question: while ignoring the details of ps-print, in these cases two strategies are to adopt
1) set variables behind a let
2) store old values with a prefix old-... and reset afterward.
Here a draft of the second way:
(defun ps-two-per-page ()
(interactive)
(require 'ps-print)
(setq old-ps-n-up-printing ps-n-up-printing
old-ps-n-up-border-p ps-n-up-border-p
old-ps-paper-type ps-paper-type
old-ps-font-size ps-font-size
old-ps-top-margin ps-top-margin
old-ps-bottom-margin ps-bottom-margin
old-ps-left-margin ps-left-margin
old-ps-right-margin ps-right-margin
old-ps-n-up-margin ps-n-up-margin
old-ps-inter-column ps-inter-column
ps-n-up-printing 2
ps-n-up-border-p nil
ps-paper-type 'letter
ps-font-size (quote (8 . 11))
ps-top-margin -20
ps-bottom-margin -35
ps-left-margin 18
ps-right-margin 18
ps-n-up-margin 1
ps-inter-column 1))
(defun ps-restore-default ()
"Get old values back"
(interactive)
(require 'ps-print)
(setq ps-n-up-printing old-ps-n-up-printing
ps-n-up-border-p old-ps-n-up-border-p
ps-paper-type old-ps-paper-type
ps-font-size old-ps-font-size
ps-top-margin old-ps-top-margin
ps-bottom-margin old-ps-bottom-margin
ps-left-margin old-ps-left-margin
ps-right-margin old-ps-right-margin
ps-n-up-margin old-ps-n-up-margin
ps-inter-column old-ps-inter-column))

How to use case and read-event with down-mouse-1

I have a function that uses (case (read-event) . . .) -- I have been unable to get down-mouse-1 to equal an integer for the duration of the function. The following is an example where down-mouse-1 yields a result of Try again instead of Hello world. All of the following examples work, except for down-mouse-1: ('f12 516); (?\s-k 517); ('f3 518); ('C-tab 519); ('C-M-s-right 520); (?m 522).
(let* (
(test (case (read-event)
('down-mouse-1 9999))))
(cond
((eq test 9999)
(message "Hello world."))
(t (message "Try again."))))
read-event never returns down-mouse-1. For a mouse click, the first event it will return will look like (down-mouse-1 ...). So you could do:
(pcase (read-event)
(`(down-mouse-1 . ,_) 9999))
Note that in my experience, 99% of the uses of read-event would be better rewritten some other way.
Not clear to me what you are trying to do. But you should not quote the keys in a case clause. E.g, use down-mouse-1, not 'down-mouse-1.

Jinja templates syntax hilighting

I'd like to adapt jinja.el to work with one-line comments using ##. But my knowlege of elisp is bad. Who can help me? What do I want: i'd like to hilite
## some text
## {% include "_template.html" %}
as a commented out strings. But it works not fully correct. 1st line of snippet looks like comment out while 2nd - not. Here is what i've got:
And here is a part of jinja.el taken from Jinja's git repo plus my regexp for ##:
(defconst jinja-font-lock-keywords
(list
; (cons (rx "{% comment %}" (submatch (0+ anything))
; "{% endcomment %}") (list 1 font-lock-comment-face))
'("{%-?\\|-?%}\\|{{\\|}}" . font-lock-preprocessor-face)
'("{# ?\\(.*?\\) ?#}" . (1 font-lock-comment-face))
'("## ?\\(.*\\)" . (1 font-lock-comment-face))
'("{#\\|#}" . font-lock-comment-delimiter-face)
'("##" . font-lock-comment-delimiter-face)
;; first word in a block is a command
OK. I found solution. Change
'("## ?\\(.*\\)" . (1 font-lock-comment-face))
to
'("## ?\\(.*\\)" . (1 font-lock-comment-face t))
ie setting 'override' parameter to true solves me question.