Re: Need help with function
Glynn Clements <[email protected]> Wed, 14 Jul 2004 08:37:03 +0100
| Newsgroups | gmane.emacs.xemacs.general |
|---|---|
| Message-ID | <[email protected]> |
[email protected] wrote: > Perhaps you could help me with this function: I need a function that puts > a string with the actual filename, a colon and the line of point into the > X Clipboard. It should look like this: > > CPTClassname.cpp:42 > > I want to paste this to DDD ... > > I came up with this so far, but emacs complains: > "Invalid function: (own-clipboard (file-name-nondirectory > buffer-file-name))" > > (defun mg-copy-position() > "Copy a string of the form filename:linenumber into the clipboard" > (interactive) > ( (own-clipboard (file-name-nondirectory buffer-file-name) ) ) > ) Omit the extra parentheses, i.e.: (defun mg-copy-position () "Copy a string of the form filename:linenumber into the clipboard" (interactive) (own-clipboard (file-name-nondirectory buffer-file-name))) In lisp, parentheses correspond to a function call rather than just grouping, so you can't just wrap extra sets of parentheses around arbitrary expressions. > As you see, It also completely lacks the combination of filename, ":" and > line... (defun mg-copy-position () "Copy a string of the form filename:linenumber into the clipboard" (interactive) (own-clipboard (format "%s:%d" (or (file-name-nondirectory buffer-file-name) "") (line-number)))) [buffer-file-name can be nil if the buffer doesn't correspond to a file.] -- Glynn Clements <[email protected]>