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))
Related
(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.
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) "
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
[]
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.
I'd like to retrieve a name of the current frame using elisp. I have discovered that name is a part of frame's properties. The properties is an associated list. I do the following:
(cdr (assoc 'name (frame-parameters)))
But instead of the expected name I receive a mixed list of the name and some properties:
#("main-1" 0 5 (face nil) 5 6 (face nil))
How can I extract "main-1" from this?
There are text properties on that string. You can use substring-no-properties to extract the plain string.
(substring-no-properties
(cdr (assoc 'name (frame-parameters))))
Note that you may not need to do this. The propertized string is still a string, and equal to its no-properties version.
See also: C-hig (elisp) Text Props and Strings RET