https://wikemacs.org/api.php?action=feedcontributions&user=188.143.232.12&feedformat=atomWikEmacs - User contributions [en]2024-03-29T11:57:44ZUser contributionsMediaWiki 1.35.14https://wikemacs.org/index.php?title=Emacs_Prelude&diff=2998Emacs Prelude2012-06-24T08:10:30Z<p>188.143.232.12: NLXjKuYgktFIRNpZMRU</p>
<hr />
<div>I'm imrpessed. You've really raised the bar with that.</div>188.143.232.12https://wikemacs.org/index.php?title=Learning_Resources&diff=2993Learning Resources2012-06-23T17:08:19Z<p>188.143.232.12: TcJGCpioPt</p>
<hr />
<div>Knocked my socks off with konwlegde!</div>188.143.232.12https://wikemacs.org/index.php?title=WikEmacs:Guidelines&diff=2983WikEmacs:Guidelines2012-06-23T04:47:58Z<p>188.143.232.12: kskhoAfqkiXHiNHADKd</p>
<hr />
<div>Between me and my husband we've owned more MP3 pleayrs over the years than I can count, including Sansas, iRivers, iPods (classic & touch), the Ibiza Rhapsody, etc. But, the last few years I've settled down to one line of pleayrs. Why? Because I was happy to discover how well-designed and fun to use the underappreciated (and widely mocked) Zunes are.</div>188.143.232.12https://wikemacs.org/index.php?title=Ruby-mode&diff=2964Ruby-mode2012-06-22T22:30:49Z<p>188.143.232.12: /* Basic setup */</p>
<hr />
<div>{{Package<br />
|name=ruby-mode<br />
|description=major mode for Ruby programming<br />
|author=Yukihiro Matsumoto<br />
|maintainer=[[FSF]]<br />
|source=http://bzr.savannah.gnu.org/lh/emacs/emacs-24/annotate/head:/lisp/progmodes/ruby-mode.el<br />
|in_emacs=yes, since Emacs 23<br />
}}<br />
<br />
'''ruby-mode''' provides Emacs font-lock, indentation, and navigation for the [[Ruby]] programming language.<br />
<br />
I am totally wowed and perpared to take the next step now.<br />
<br />
== Helpful keybindings ==<br />
<br />
/ do you use several plguins in your theme? it looks like a conflict because of different plguins!Ib4m working with the theme for the last 2 weeks and I have absolutely no problems with it, except the navigation.php<br />
<br />
== See Also ==<br />
<br />
* [[ruby-end]]<br />
* [[ruby-block]]<br />
* [[inf-ruby]]<br />
* [[rinari]]<br />
<br />
You lost me, buddy. I mean, I suppose I get what youre daeclring. I realize what you're saying, but you just seem to have forgotten that you'll find some other persons within the world who look at this matter for what it genuinely is and may not agree with you. You may well be turning away a decent amount of folks who might have been supporters of your website.</div>188.143.232.12https://wikemacs.org/index.php?title=Bookmarks&diff=2963Bookmarks2012-06-22T22:00:04Z<p>188.143.232.12: rKcBFggReQU</p>
<hr />
<div>try a vegeterian diet, it helps get rid of fat, bulk.avoid salts. you still can have portein just notfrom meat. try fish if you have to get portein.other than that, any kind of stop, and jumps, repeatedwill help build the muscles you need. do it for 20 minutesever other day. you need to give it time to recover.you may want to increate the 30 minutes of jumpingto 40 once you see improved jumping.Play lots of basketballIf you play a lot of ball, that will tranlate into being in better shape. There's no way your vertical leap will improve if you aren't in good shape. Also, there are lots of quick movements you make in a game that you can't recreate outside of actual game play. These help build your overall basketball abilities, as well as your athleticism (explosiveness, jumping ability, etc.).- Workout with a jump ropeIt's an old school exercise, but it works. Jumping rope is a great way to build stamina, and work on your leg strength. In addition, it builds jumping ability (explosiveness, calf strength, etc.). It's really a great exercise.- Run stadium stairsAnother old school exericse and a great one. Running stadium stairs can really help your vertical leap because it build stamina, leg strength, and when done right, explosiveness. To work on explosiveness, use bounding movements. In otherwords, don't just get from one step the the next, but really leap and bound up from one step to the next.- Wall sits and squatsStrength training (like wall sits and squats) will help you build leg strength, which is a key component of athletic fitness, and therefore jumping ability. Remember to only use a weight that is comfortable for you, and to always have a trainer or training partner work out with you. You don't want to get hurt lifting too much weight, or lifting it improperly.- Explosive leapsThis is a great type of exercises. Do these at a park, or on a football field so that you are cushioned by the soft grass surface.One-legged jumps are done like this: leap as high as possible off of one foot, then come down and immediately leap as high as possible off the other leg. Repeat this for 10 to 15 jumps.Two-legged leaps are done like this: squat down so you are in the triple threat position. Now explode up and off the ground as if you are reaching for a rebound. Come down, gather yourself for a second or two, then leap up again, as high as possible. Do this 8 to 10 times.Remember, vertical leap is part leg strength and part explosiveness. In fact, the explosiveness part is the more important of the two. It's not about the size of your leg muscles, or how much weight you can put up in the gym. It's about your athletic ability, coordination, and your ability to explode up and off the ground.</div>188.143.232.12https://wikemacs.org/index.php?title=Feed_reading&diff=2955Feed reading2012-06-22T21:00:20Z<p>188.143.232.12: bhDNiKNaDYdzg</p>
<hr />
<div>Great video Graham. I remembered this from Pro Tools Boot Camp, but I had pettry much forgotten what shuffle and spot mode do. Speaking of Pro Tools 10. I have the ability to upgrade to pro tools 10 for free because I bought a student pro tools 9 upgrade from pro tools 8 (same for any type of student purchase of pro tools 9). I am gonna be honest, I am very happy with Pro tools 9 and it runs on my mac almost completely without a hitch. When I first got the offer from avid I thought, No way, why risk getting a new version that may not run as smoothly as my current set up does, when I am perfectly happy with what I have now. However, I read some reviews and learned what the upgrades and additions are, and some of them sound really cool (regions become clips and you can adjust the volume of each clip/region, add plugins, etc. separately without need for automation), not necessities for me, but would be cool to have. Also, if I don't upgrade now for free, there will probably come a time when they are no longer offering free upgrades for those who bought pro tools 9 at a student price, then I would have to pay the full upgrade price. What would you guys do in my shoes?</div>188.143.232.12https://wikemacs.org/index.php?title=WikEmacs:Guidelines&diff=2946WikEmacs:Guidelines2012-06-22T20:28:32Z<p>188.143.232.12: lwTwTmhM</p>
<hr />
<div>I literally jmpued out of my chair and danced after reading this!</div>188.143.232.12https://wikemacs.org/index.php?title=Emacs_Lisp_Cookbook&diff=2941Emacs Lisp Cookbook2012-06-22T19:33:43Z<p>188.143.232.12: /* Numbers */</p>
<hr />
<div>This page contains snippets of code that demonstrate basic [[Emacs Lisp]]<br />
programming operations in the spirit of O'Reilly's Cookbook<br />
series of books. For every task addressed, a worked-out solution<br />
is presented as a short, focused, directly usable piece of code.<br />
<br />
All this stuff can be found elsewhere, but it is scattered about in<br />
libraries, manuals, etc. It would be helpful to have it here in one<br />
spot.<br />
<br />
These recipes should be pastable into the '''*scratch*''' buffer so that<br />
users can hit '''C-j''' and evaluate them step by step.<br />
<br />
== Strings ==<br />
<br />
The empty string (zero-length string, null string, ...):<br />
<br />
<syntaxhighlight lang="lisp"><br />
(zerop (string-match "" "")) ;; O(n)<br />
==> t<br />
<br />
(string-equal "" "") ;; O(n)?<br />
==> t<br />
<br />
(equal "" "") ;; O(n)?<br />
==> t<br />
<br />
(zerop (length "")) ;; O(1)<br />
==> t<br />
<br />
(eq "" "") ;; O(1)<br />
==> t<br />
</syntaxhighlight><br />
<br />
As a space and performance optimization, Emacs keeps an intern-ed copy<br />
of the empty string as a single object<br />
<br />
<syntaxhighlight lang="lisp"><br />
(eq "" (purecopy ""))<br />
==> t<br />
<br />
(eq "" (propertize "" 'face 'italic))<br />
==> t<br />
</syntaxhighlight><br />
<br />
=== Strings vs buffer content ===<br />
<br />
While it is quite common in other programming languages to work on<br />
strings contained in variables in Emacs it is even more idiomatic to<br />
work on strings in buffers. That's why the following contains examples<br />
of both.<br />
<br />
=== Substrings ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(substring "abcdefg" 0 3)<br />
==> "abc"<br />
(substring "abcdefg" -3 -1)<br />
==> "ef"<br />
</syntaxhighlight><br />
<br />
The TO argument is optional:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(substring "abcdefg" -3)<br />
==> "efg"<br />
</syntaxhighlight><br />
<br />
Buffers:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(with-temp-buffer<br />
(insert "abcdefg")<br />
(buffer-substring 2 4))<br />
==> "bc"<br />
</syntaxhighlight><br />
<br />
=== Processing characters ===<br />
<br />
Reversing a string:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(string-to-list "foo")<br />
==> (102 111 111)<br />
(reverse (string-to-list "foo"))<br />
==> (111 111 102)<br />
(apply 'string (reverse (string-to-list "foo")))<br />
==> "oof"<br />
</syntaxhighlight><br />
<br />
See CharacterProcessing and StringModification. See [[tr]] for an example of you sometimes need to mix strings and characters.<br />
<br />
Looking at characters in buffers:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(with-temp-buffer<br />
(insert "abcdefg")<br />
(goto-char (point-min))<br />
(while (not (= (char-after) ?b))<br />
(forward-char))<br />
(point))<br />
==> 2<br />
</syntaxhighlight><br />
<br />
=== Trim whitespace ===<br />
<br />
Trim whitespace from the end of a string:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(setq test-str "abcdefg ")<br />
(when (string-match "[ \t]*$" test-str)<br />
(message (concat "[" (replace-match "" nil nil test-str) "]")))<br />
</syntaxhighlight><br />
<br />
Trim whitespace from a string with a Perl-like chomp function:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun chomp (str)<br />
"Chomp leading and tailing whitespace from STR."<br />
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'"<br />
str)<br />
(setq str (replace-match "" t t str)))<br />
str)<br />
</syntaxhighlight><br />
<br />
=== Splitting strings ===<br />
<br />
The 'split-string' function is defined in 'subr.el' as<br />
<br />
<source lang="lisp"><br />
(defun split-string (string &optional separators omit-nulls)<br />
...)<br />
</source><br />
<br />
where 'separators' is a regular expression describing where to split the string. 'separators' defaults to white-space characters (spaces, form feeds, tabs, newlines, carriage returns, and vertical tabs). If 'omit-nulls' is set as 't' then zero-length strings are deleted from output.<br />
<br />
<source lang="lisp"><br />
(split-string "1 thing 2 say 3 words 4 you" "[1-9]")<br />
==> ("" " thing " " say " " words " " you")<br />
</source><br />
<br />
Omitting nulls:<br />
<source lang="lisp"><br />
(split-string "1 thing 2 say 3 words 4 you" "[1-9]" t)<br />
(" thing " " say " " words " " you")<br />
</source><br />
<br />
=== Joining strings ===<br />
<br />
Use `mapconcat' to join a list into a string using a separator ("glue") between elements in the string.<br />
<br />
Example:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(mapconcat 'identity '("" "home" "alex " "elisp" "erc") "/")<br />
==> "/home/alex /elisp/erc"<br />
</syntaxhighlight><br />
<br />
=== Serialization ===<br />
<br />
The basic idea is to convert forms to strings with `prin1-to-string' and convert it back from a string with `read'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(length (read (prin1-to-string (make-list 1000000 '(x)))))<br />
==> 1000000<br />
<br />
(read (prin1-to-string "Hello World!"))<br />
==> "Hello World!"<br />
</syntaxhighlight><br />
<br />
This only works in the simplest cases. Unfortunately, this doesn't work for all Emacs data types for programming or the editor.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(read (prin1-to-string (make-hash-table))) ;; Error before Emacs 23.<br />
==> #s(hash-table size 65 test eql rehash-size 1.5 [...] data ())<br />
<br />
(read (prin1-to-string (current-buffer)))<br />
==> Lisp error: (invalid-read-syntax "#")<br />
</syntaxhighlight><br />
<br />
=== Formatting ===<br />
<br />
== Killing text ==<br />
<br />
As the Emacs Lisp Manual says, "Most of the kill commands are primarily for<br />
interactive use [...] When you need to delete text for internal<br />
purposes within a Lisp function, you should normally use deletion<br />
functions, so as not to disturb the kill ring contents."<br />
<br />
The following mimic the `kill-' commands but without disturbing the kill ring.<br />
<br />
=== Delete region ===<br />
<br />
The Lisp equivalent of `kill-region' (`C-w') but without kill ring side effects::<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (region-beginning) (region-end))<br />
</syntaxhighlight> <br />
<br />
According to the ElispManual, "Few programs need to use the<br />
`region-beginning' and `region-end' functions." This is because<br />
Lisp code should not rely on nor "alter the mark unless altering<br />
the mark is part of the user-level functionality of the<br />
command. (And, in that case, this effect should be documented.)<br />
To remember a location for internal use in the Lisp program,<br />
store it in a Lisp variable. For example: [...]"<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-line 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight><br />
<br />
=== Delete line ===<br />
<br />
The equivalent of `kill-line' (`C-k') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-line 1)<br />
(forward-char -1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight><br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point)<br />
(save-excursion<br />
(forward-line 1)<br />
(forward-char -1)<br />
(point)))<br />
</syntaxhighlight> <br />
<br />
Or simplest of all,<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point) (line-end-position))<br />
</syntaxhighlight> <br />
<br />
The examples with `forward-line' are shown because the paradigm is used later, see below.<br />
<br />
=== Delete line backwards ===<br />
<br />
The equivalent of killing the line backwards (`C-0 C-k') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-line 0)<br />
(delete-region (point) beg))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (save-excursion<br />
(forward-line 0)<br />
(point))<br />
(point))<br />
</syntaxhighlight> <br />
<br />
Or simplest of all,<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (line-beginning-position) (point))<br />
</syntaxhighlight> <br />
<br />
<br />
=== Delete line to next line ===<br />
<br />
The equivalent of killing the line and the newline (`C-1 C-k') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-line 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point)<br />
(save-excursion<br />
(forward-line 1)<br />
(point)))<br />
</syntaxhighlight> <br />
<br />
=== Delete whole line ===<br />
<br />
The equivalent of `kill-whole-line' (`C-S-DEL') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (progn (forward-line 0)<br />
(point))))<br />
(forward-line 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (save-excursion<br />
(forward-line 0)<br />
(point))<br />
(save-excursion<br />
(forward-line 1)<br />
(point)))<br />
</syntaxhighlight> <br />
<br />
Or simplest of all,<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (line-beginning-position) (line-end-position))<br />
</syntaxhighlight> <br />
<br />
=== Delete word ===<br />
<br />
The equivalent of `kill-word' (`M-d') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-word 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point)<br />
(save-excursion<br />
(forward-word 1)<br />
(point)))<br />
</syntaxhighlight> <br />
<br />
=== Delete sentence ===<br />
<br />
The equivalent of `kill-sentence' (`M-k') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-sentence 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point)<br />
(save-excursion<br />
(forward-sentence 1)<br />
(point)))<br />
</syntaxhighlight><br />
<br />
Забавно!недавно был очень похожий случай.есть функция:string addsign(char sign, const srnitg & s){1) return sign+s; // так нельзя2) return srnitg(s1)+s; //тоже нельзя3) return srnitg(s1, 1)+s;// только так можно... но блин не сразу допетриваешь }Решил это сам проверить, на компиляторе gcc 3.4.2.вот такая программулинка:#include <string>#include <stdio.h>using namespace std;string addsign(char s1, const srnitg & s){//1)return s1+s; // так нельзя//2)return srnitg(s1)+s; //тоже нельзя//3)return srnitg(s1, 1)+s;// только так можно... но блин не сразу допетриваешь//4)return srnitg(&s1, 1)+s;}int main(int n, char **args){ srnitg text = "1.9876"; srnitg res = addsign('-', text); puts(res.c_str()); return 0;}выдала мне срвсем другое:первый вариант (как "нельзя") выдал правильный результат: -1.9876, второй вариант - ошибку компиляции, а третий(который "только так и можно") дал нечто невразумительное - кучу смеющихся рожиц и в конце-число 1.9876. Мне даже непонятно, как у автора сообщения получился нормальный результат.Последний (4-ый, "мой" вариант) дал тоже верный результат: -1.9876<br />
<br />
== Dates and times ==<br />
<br />
=== Get today's date ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-time-string "%d %B %Y")<br />
</syntaxhighlight><br />
<br />
or <br />
<br />
<syntaxhighlight lang="lisp"><br />
(eshell/date)<br />
</syntaxhighlight><br />
<br />
=== Formatting dates ===<br />
<br />
Use the function `format-time-string' which is a build in function in both Emacsen and works like `strftime':<br />
<br />
<syntaxhighlight lang="lisp"><br />
;; Year-Month-Day:<br />
(insert (format-time-string "%Y-%m-%d"))<br />
;; Hour:Minutes:Seconds<br />
(insert (format-time-string "%H-%M-%S"))<br />
</syntaxhighlight> <br />
<br />
=== Conversions ===<br />
<br />
Read a date from a string.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((time (date-to-time "Tue, 27-Sep-83 12:35:59 EST")))<br />
(set-time-zone-rule t) ;; Use Universal time.<br />
(prog1 (format-time-string "%Y-%m-%d %T UTC" time)<br />
(set-time-zone-rule nil))) ;; Reset to default time zone.<br />
==> "1983-09-27 17:35:59 UTC"<br />
</syntaxhighlight> <br />
<br />
Decode a time object.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(decode-time (date-to-time "Tue, 27-Sep-83 12:35:59 EST"))<br />
==> (59 35 13 27 9 1983 2 t -14400)<br />
</syntaxhighlight> <br />
<br />
Get the seconds from the unix epoch.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((time (date-to-time "13 Feb 2009 23:31:30 UTC")))<br />
(float-time time))<br />
==> 1234585890.0<br />
</syntaxhighlight> <br />
<br />
Find the date for seconds from the unix epoch.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-time-string "%Y-%m-%d %T UTC" (seconds-to-time 1234585890))<br />
==> "2009-02-13 23:31:30 UTC"<br />
</syntaxhighlight> <br />
<br />
Find the date 30 seconds in the future.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-time-string "%Y-%m-%d %T UTC" (time-add (current-time)<br />
(seconds-to-time 30)))<br />
==> "2012-02-13 10:07:11 UTC"<br />
</syntaxhighlight> <br />
<br />
Formatting elapsed time in years, days, hours, minutes and seconds.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-seconds "%Y %D %h:%m:%s" (1- (* 367 24 3600)))<br />
==> "1 year 1 day 23:59:59"<br />
</syntaxhighlight> <br />
<br />
Find the days between two dates.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((days1 (time-to-days (date-to-time "Tue, 27-Sep-83 12:35:59 EST")))<br />
(days2 (time-to-days (date-to-time "2009-02-13 23:31:30 UTC"))))<br />
(- days2 days1))<br />
==> 9271<br />
</syntaxhighlight> <br />
<br />
Getting the day in the year.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(time-to-day-in-year (current-time))<br />
==> 44<br />
</syntaxhighlight> <br />
<br />
Build a date based on the day of the year.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-time-string "%j"<br />
(encode-time 0 0 0 44 1 2012))<br />
==> "044"<br />
</syntaxhighlight> <br />
<br />
=== Timers ===<br />
<br />
TODO<br />
<br />
Its funny that your example uses std::string beaucse it has the solution you're looking for.What you're trying to do is initialize a class member before initializing the base class, and you found that you can't. The typical way to get around this is to abandon hope of extending Foo and implement the wrapper in terms of Foo. (has-a vs. is-a) This solution has the annoyance of you needing to redeclare each and every method you want to use and then forwarding those calls to Foo, and you won't be able to use a FooWrapper in place of a Foo as well, meaning you may need to change a ton of references in your code. However, all you have to do is have FooWrapper expose its underlying Foo and you're good. (kinda like what string::c_str() does)Check out your copy of Effective C++. From the TOC I think item 40 discusses this.<br />
<br />
== Sequences ==<br />
<br />
Datatypes used to represent sequences of things:<br />
<br />
_____________________________________________<br />
| |<br />
| Sequence |<br />
| ______ ________________________________ |<br />
| | | | | |<br />
| | List | | Array | |<br />
| | | | ________ ________ | |<br />
| |______| | | | | | | |<br />
| | | Vector | | String | | |<br />
| | |________| |________| | |<br />
| | ____________ _____________ | |<br />
| | | | | | | |<br />
| | | Char-table | | Bool-vector | | |<br />
| | |____________| |_____________| | |<br />
| |________________________________| |<br />
|_____________________________________________|<br />
<br />
<br />
=== Lists ===<br />
<br />
List basics are explained on ListStructure.<br />
Lists can shrink and grow, but access to elements towards the end of the list is slow if the list is long.<br />
<br />
Use `cons' to append a new element to the front of a list.<br />
Use `nth' to access an element of the list.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((words '("fight" "foo" "for" "food!")))<br />
(when (string= "foo" (nth 1 words))<br />
(setq words (cons "bar" words)))<br />
words)<br />
==> ("bar" "fight" "foo" "for" "food!")<br />
</syntaxhighlight> <br />
<br />
See ListModification for more ways of changing a list.<br />
<br />
Iteration:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((result))<br />
(dolist (word '("fight" "foo" "for" "food!"))<br />
(when (string-match "o" word)<br />
(setq result (cons word result))))<br />
(nreverse result))<br />
==> ("foo" "for" "food!")<br />
</syntaxhighlight> <br />
<br />
Note how `cons' adds an element to the front of the list,<br />
so that usually the list has to be reversed after the loop.<br />
`nreverse' is particularly efficient because it does this<br />
destructively by swiveling pointers around. See<br />
DestructiveOperations for more about this.<br />
<br />
Copying:<br />
<br />
Use `copy-sequence' to make a copy of a list that won't change the<br />
elements of the original.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let* ((orig '((1 2) (3 4)))<br />
(copy (copy-sequence orig)))<br />
(setcdr copy '((5 6)))<br />
(list orig copy))<br />
==> (((1 2) (3 4)) ((1 2) (5 6)))<br />
</syntaxhighlight> <br />
<br />
However, the elements in the copy are still from the original.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let* ((orig '((1 2) (3 4)))<br />
(copy (copy-sequence orig)))<br />
(setcdr (cadr copy) '(0))<br />
(list orig copy))<br />
==> (((1 2) (3 0)) ((1 2) (3 0)))<br />
</syntaxhighlight> <br />
<br />
The function `copy-tree' is the recursive version of `copy-sequence'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let* ((orig '((1 2) (3 4)))<br />
(copy (copy-tree orig)))<br />
(setcdr (cadr copy) '(0))<br />
(list orig copy))<br />
==> (((1 2) (3 4)) ((1 2) (3 0)))<br />
</syntaxhighlight> <br />
<br />
Filtering:<br />
<br />
Emacs Lisp doesn't come with a `filter' function to keep elements that satisfy a conditional and excise the elements that do not satisfy it. One can use `mapcar' to iterate over a list with a conditional, and then use `delq' to remove the `nil' values.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun my-filter (condp lst)<br />
(delq nil<br />
(mapcar (lambda (x) (and (funcall condp x) x)) lst)))<br />
</syntaxhighlight> <br />
<br />
Therefore,<br />
<br />
<syntaxhighlight lang="lisp"><br />
(my-filter 'identity my-list)<br />
</syntaxhighlight> <br />
<br />
is equivalent to<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delq nil my-list)<br />
</syntaxhighlight> <br />
<br />
For example:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((num-list '(1 'a 2 "nil" 3 nil 4)))<br />
(my-filter 'numberp num-list))<br />
==> (1 2 3 4)<br />
</syntaxhighlight> <br />
<br />
Actually the package cl-seq contains the functions `remove-if' and `remove-if-not'. The latter can be used instead of `my-filter'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((num-list '(1 'a 2 "nil" 3 nil 4)))<br />
(remove-if-not 'numberp num-list))<br />
==> (1 2 3 4)<br />
<br />
(let ((num-list '(1 'a 2 "nil" 3 nil 4)))<br />
(remove-if 'numberp num-list))<br />
==> ((quote a) "nil" nil)<br />
</syntaxhighlight> <br />
<br />
As an example here is the quick sort algorithm:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun quicksort (lst)<br />
"Implement the quicksort algorithm."<br />
(if (null lst) nil<br />
(let* ((spl (car lst))<br />
(rst (cdr lst))<br />
(smalp (lambda (x)<br />
(< x spl))))<br />
(append (quicksort (remove-if-not smalp rst))<br />
(list spl)<br />
(quicksort (remove-if smalp rst))))))<br />
<br />
(quicksort '(5 7 1 3 -9 8 7 -4 0))<br />
==> (-9 -4 0 1 3 5 7 7 8)<br />
</syntaxhighlight> <br />
<br />
Tranposing:<br />
<br />
Convert multiple lists into a list <br />
<br />
<syntaxhighlight lang="lisp"><br />
((lambda (&rest args)<br />
(mapcar (lambda (n)<br />
(delq nil (mapcar (lambda (arg) (nth n arg)) args)))<br />
(number-sequence 0 (1- (apply 'max (mapcar 'length args))))))<br />
'(1 2 3) '(a b c) '(A B C))<br />
==> ((1 a A) (2 b B) (3 c C))<br />
</syntaxhighlight> <br />
<br />
A more concise version is possible with the the higher-arity version of mapcar available with the `cl' library.<br />
<br />
<syntaxhighlight lang="lisp"><br />
((lambda (&rest args)<br />
(apply (function mapcar*) (function list) args))<br />
'(1 2 3) '(a b c) '(A B C))<br />
==> ((1 a A) (2 b B) (3 c C))<br />
</syntaxhighlight> <br />
<br />
Searching:<br />
<br />
Simply checking for existence of a value in a list can be done with<br />
`member' or `memq'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((words '("fight" "foo" "for" "food!")))<br />
(car (member "for" words)))<br />
==> "for"<br />
<br />
(let ((re "\\wo\\b")<br />
(words '("fight" "foo" "for" "food!")))<br />
(consp (memq t<br />
(mapcar (lambda (s) (numberp (string-match re s))) words))))<br />
==> t<br />
</syntaxhighlight> <br />
<br />
In the latter, a more efficient algorithm would use a loop (a non-local exit).<br />
<br />
I don't think so. Normally you will open it up with latest veorisn, then save it in an earlier veorisn, that wat you can retain the 2008 veorisn with all the new options, and then convert it to an earlier. The improvements which are not handled by an earlier veorisn will be prompted when you try to save. You can lose layers or part of layers.<br />
<br />
=== Vectors ===<br />
<br />
Vectors are fixed in size but elements can be accessed in constant time.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((words ["fight" "foo" "for" "food!"]))<br />
(when (string= "foo" (aref words 1))<br />
(aset words 1 "bar"))<br />
words)<br />
==> ["fight" "bar" "for" "food!"]<br />
</syntaxhighlight> <br />
<br />
== Hashes ==<br />
<br />
Hashes map keys to values. In a way they are similar to alists, except<br />
they are more efficient for a large number of keys.<br />
<br />
More info is available on the HashMap page.<br />
<br />
=== Storing and retrieving keys and values ===<br />
<br />
By default, hash tables use `eql' to compare keys. This is not appropriate<br />
for strings: ##(eql "alex" "alex")## ==> nil. Thus, use `equal' in these cases:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((nick-table (make-hash-table :test 'equal)))<br />
(puthash "kensanata" "Alex Schroeder" nick-table)<br />
(gethash "kensanata" nick-table))<br />
==> "Alex Schroeder"<br />
</syntaxhighlight> <br />
<br />
Iterate:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((nick-table (make-hash-table :test 'equal))<br />
nicks)<br />
(puthash "kensanata" "Alex Schroeder" nick-table)<br />
(puthash "e1f" "Luis Fernandes" nick-table)<br />
(puthash "pjb" "Pascal J. Bourguignon" nick-table)<br />
(maphash (lambda (nick real-name)<br />
(setq nicks (cons nick nicks)))<br />
nick-table)<br />
nicks)<br />
==> ("pjb" "e1f" "kensanata")<br />
</syntaxhighlight> <br />
<br />
=== Sorting keys ===<br />
<br />
Use `maphash' to build up a list of keys, sort it, and then loop through<br />
the list:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((nick-table (make-hash-table :test 'equal))<br />
nicks)<br />
(puthash "kensanata" "Alex Schroeder" nick-table)<br />
(puthash "e1f" "Luis Fernandes" nick-table)<br />
(puthash "pjb" "Pascal J. Bourguignon" nick-table)<br />
(maphash (lambda (nick real-name)<br />
(setq nicks (cons nick nicks)))<br />
nick-table)<br />
(mapcar (lambda (nick)<br />
(concat nick " => " (gethash nick nick-table)))<br />
(sort nicks 'string<)))<br />
==> ("e1f => Luis Fernandes"<br />
"kensanata => Alex Schroeder"<br />
"pjb => Pascal J. Bourguignon")<br />
</syntaxhighlight> <br />
<br />
== Files ==<br />
<br />
=== Read ===<br />
<br />
Processing a file is usually done with a temporary buffer:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun process-file (file)<br />
"Read the contents of a file into a temp buffer and then do<br />
something there."<br />
(when (file-readable-p file)<br />
(with-temp-buffer<br />
(insert-file-contents file)<br />
(goto-char (point-min))<br />
(while (not (eobp))<br />
;; do something here with buffer content<br />
(forward-line)))))<br />
</syntaxhighlight> <br />
<br />
On the chance that a buffer may already be actively visiting the file,<br />
consider using `find-file-noselect'<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun file-string (file)<br />
"Read the contents of a file and return as a string."<br />
(with-current-buffer (find-file-noselect file)<br />
(buffer-string)))<br />
</syntaxhighlight> <br />
<br />
=== Write ===<br />
<br />
To write something to a file you can create a temporary buffer, insert the things to write there and write the buffer contents to a file. The following example read a string and a filename (with completion, but doesn't need to exist, see InteractiveCodeChar F) and write the string to that file.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun write-string-to-file (string file)<br />
(interactive "sEnter the string: \nFFile to save to: ")<br />
(with-temp-buffer<br />
(insert string)<br />
(when (file-writable-p file)<br />
(write-region (point-min)<br />
(point-max)<br />
file))))<br />
</syntaxhighlight> <br />
<br />
Maybe you are interested in word-count.el. It's cnirately to much foryour use-case but it is a great tool if you have some target lengthfor a document (e.g. diary entries).What I'm really missing in Emacs is some usage statistics. I canalready get an overview over my keybind habits with keyfreq but Iwould like that to be more comprehensive. Average buffer-length, timespent in different modes, time spent in files that are part of acertain directory, lines added etc. Maybe I'm just addicted to lifestatistics and this is not really useful. Who knows.<br />
<br />
=== Searching ===<br />
<br />
If you don't have grep, then you may need to write some Lisp which can find a match in a file.<br />
<br />
<syntaxhighlight lang="lisp"><br />
;; Visit file unless its already open.<br />
(with-current-buffer (find-file-noselect "~/.emacs")<br />
(save-excursion ;; Don't change location of point.<br />
(goto-char (point-min)) ;; From the beginning...<br />
(if (re-search-forward ".*load-path.*" nil t 1)<br />
(match-string-no-properties 0)<br />
(error "Search failed"))))<br />
==> "(add-to-list 'load-path \"/usr/share/emacs/site-lisp/\")"<br />
</syntaxhighlight> <br />
<br />
=== Filter ===<br />
<br />
=== Locking ===<br />
<br />
=== Stat ===<br />
<br />
An interface to the kernel's stat(2) is provided by the function file-attributes. The way times are represented may be a bit unexpected, though.<br />
<br />
=== Deleting ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(if (file-exists-p filename)<br />
(delete-file filename))<br />
</syntaxhighlight> <br />
<br />
=== Copy, move and rename ===<br />
<br />
== Directories ==<br />
<br />
=== Traversing ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun walk-path (dir action)<br />
"walk DIR executing ACTION with (dir file)"<br />
(cond ((file-directory-p dir)<br />
(or (char-equal ?/ (aref dir(1- (length dir))))<br />
(setq dir (file-name-as-directory dir)))<br />
(let ((lst (directory-files dir nil nil t))<br />
fullname file)<br />
(while lst<br />
(setq file (car lst))<br />
(setq lst (cdr lst))<br />
(cond ((member file '("." "..")))<br />
(t<br />
(and (funcall action dir file)<br />
(setq fullname (concat dir file))<br />
(file-directory-p fullname)<br />
(walk-path fullname action)))))))<br />
(t<br />
(funcall action<br />
(file-name-directory dir)<br />
(file-name-nondirectory dir)))))<br />
<br />
(defun walk-path-visitor (dir file)<br />
"Called by walk-path for each file found"<br />
(message (concat dir file)))<br />
<br />
(walk-path "~/" 'walk-path-visitor)<br />
</syntaxhighlight> <br />
<br />
=== Path splitting ===<br />
<br />
Splitting the path can be done with `split-string' and with the slash. Previously, Emacs would determine the character separating directory names with `directory-sep-char'. However, the variable is obselete with Emacs 21.1.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(split-string default-directory "/")<br />
==> ("" "usr" "share" "emacs" "22.2" "lisp" "")<br />
</syntaxhighlight><br />
<br />
For splitting a path variable, Emacs already has the `parse-colon-path' function.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(parse-colon-path (getenv "PATH"))<br />
==> ("/usr/lib/qt-3.3/bin/" "/usr/kerberos/bin/" "/usr/local/bin/"<br />
"/usr/bin/" "/bin/" "/usr/local/sbin/" "/usr/sbin/" "/sbin/")<br />
</syntaxhighlight><br />
<br />
== Processes ==<br />
<br />
=== Running a program ===<br />
<br />
Run a command without caring about its output.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(async-shell-command "emacs")<br />
</syntaxhighlight> <br />
<br />
Run a command and put its output in the current buffer.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(shell-command "seq 8 12 | sort" t)<br />
10<br />
11<br />
12<br />
8<br />
9<br />
</syntaxhighlight> <br />
<br />
Run a command and put its output in a new buffer.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(shell-command "seq 8 12 | sort"<br />
(get-buffer-create "*Standard output*"))<br />
</syntaxhighlight> <br />
<br />
Run a command return its output as a string.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(shell-command-to-string "seq 8 12 | sort")<br />
</syntaxhighlight> <br />
<br />
XEmacs also comes with `exec-to-string'.<br />
<br />
=== Handling signals ===<br />
<br />
== Sockets ==<br />
<br />
=== Tcp client ===<br />
<br />
=== Tcp server ===<br />
<br />
Perhaps EmacsEchoServer and EmacsDaytimeServer can be useful here.<br />
<br />
== Keyboard events ==<br />
<br />
* Call function bound to key<br />
<br />
<syntaxhighlight lang="lisp"><br />
(funcall (key-binding (kbd "M-TAB")))<br />
</syntaxhighlight> <br />
<br />
or<br />
<br />
<syntaxhighlight lang="lisp"><br />
(call-interactively (key-binding (kbd "M-TAB")))<br />
</syntaxhighlight> <br />
<br />
[[Category:Customization]]<br />
[[Category:Intermediate]]</div>188.143.232.12https://wikemacs.org/index.php?title=Learning_Resources&diff=2937Learning Resources2012-06-22T19:01:08Z<p>188.143.232.12: VRjZvLEO</p>
<hr />
<div>An impressive share, I just given this onto a cloaelgue who was doing a bit of analysis on this. And he actually purchased me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the deal with! However yeah Thnkx for spending the time to debate this, I really feel strongly about it and love reading extra on this topic. If doable, as you become expertise, would you thoughts updating your weblog with more particulars? It is highly helpful for me. Huge thumb up for this blog put up!</div>188.143.232.12https://wikemacs.org/index.php?title=Template:NewPage&diff=2935Template:NewPage2012-06-22T18:22:39Z<p>188.143.232.12: /* Windows */</p>
<hr />
<div>'''{{{1}}}''' is a wonderful mode which does wonderful things.<br />
<br />
<!-----DONT REMOVE ANYTHING FROM THIS TEMPLATE ------------------------------><br />
<!-----YOU CAN DELETE STUFF THAT ARE USELESS IN THE FINAL PAGE YOU ARE WRITING -------><br />
<!-----FEW MONTHS, YEARS FROM WE CAN DELETE STUFF. NOT NOW ------------------><br />
<!-----YOU DON"T WANT WIKEMACS TO BE ANOTHER EMACSWIKI RIGHT ------------------><br />
<!-----PLEASE BE PATIENT AND CO-OPERATE FOR GREATER GOOD ------------------><br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
== Basic setup ==<br />
<br />
Install these third party libraries or read this section before proceeding.<br />
<br />
== Helpful keybindings ==<br />
<br />
; {{Keys|C-x C-c}}<br />
: Quit Emacs.<br />
<br />
; {{CommandKeys|C-x C-s|save-buffer}}<br />
: Save buffer.<br />
<br />
<!-------------------------------------------------------------------------><br />
== Common Customization ==<br />
<!-- Customization common to all platforms goes here --><br />
<br />
=== Customization 1 ===<br />
<source lang="lisp"><br />
(message "This stuff will go in your .emacs")<br />
</source><br />
<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
== [[GNU/Linux]] ==<br />
<!-- Customization/Notes specific to GNU/Linux goes here --><br />
<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
== [[OS X]] ==<br />
<!-- Customization/Notes specific to OS X goes here --><br />
<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
I love the idea of PostAvatar, because I have a ton of LJ icons I'd like to be able to use on my WP blog. But for some resaon, my icons always appear centered in the top of my post the icon doesn't float left and allow the text to wrap, which is what I want it to do. Is this normal? I'm not really all that fantastic with CSS, so I have no idea how to make it float and wrap. If you have any ideas, that would be fantastic. Thanks!<br />
<br />
== [[Emacs-24]] ==<br />
<!-- Customization/Notes specific to Emacs-24 --><br />
<!-- Recent revision should come first. This way important information stays at top --><br />
<br />
<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
== [[Emacs-23]] ==<br />
<!-- Customization/Notes specific to Emacs-22 --><br />
Emacs-23 is not as great as Emacs-24. You will have these problems and you can workaround it this way.<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
== Recommended Reading ==<br />
<!-- Only internal links. DO NOT insert EXTERNAL LINKS --><br />
* [[Internal Link1]]<br />
* [[Internal Link2]]<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
== Project Pages ==<br />
* [http://bazaar.canonical.com/en/ Bazaar]<br />
* [http://doc.bazaar-vcs.org/bzr.dev/en/user-guide/index.html Bzr Users Guide]<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
== Tutorial Pages ==<br />
;[http://wiki.bazaar.canonical.com/EmacsTips Emacs as commit message editor] <br />
:Tips for setting up Emacs as Bazaar commit editor.<br />
<br />
<!-------------------------------------------------------------------------><br />
<!-- Add categories based on user-level (beginner etc), user-role (programming, emacs contributor etc), platform (windows, linux etc), work flow (text editing, document authoring etc) or package type (built-in or third party) --><br />
<br />
[[Category:TestCategory1]][[Category:TestCategory2]]<br />
<br />
<!-- When copying this template, ignore everything below here! --><br />
<noinclude>[[Category:Templates]]</noinclude></div>188.143.232.12https://wikemacs.org/index.php?title=Template:CommandKeys&diff=2932Template:CommandKeys2012-06-22T17:44:20Z<p>188.143.232.12: VUUpPlzKgERnIYpWep</p>
<hr />
<div>The Progress of Education Reform Summer Learning PDF For a long time, the issue of summer lnnierag has waited in the wings, like a fully prepared understudy, ready to jump in and take the stage should the star need a back-up. Recently, though, summer lnnierag has moved into the spotlight — and at the same time, the script is changing. Instead of memorizing and mimicking the star’s lines, summer lnnierag is writing its own script. Transcending the punitive and remedial model of summer school, summer lnnierag’s new form is an artful blend of core academic lnnierag, hands-on activities, 21st century skills, arts, sports and meaningful relationships. (Brenda McLaughlin and Jeffrey Smink, National Center for Summer Learning at Johns Hopkins University, June 2009)</div>188.143.232.12https://wikemacs.org/index.php?title=Emacs_Lisp_Cookbook&diff=2928Emacs Lisp Cookbook2012-06-22T16:48:39Z<p>188.143.232.12: /* Association lists */</p>
<hr />
<div>This page contains snippets of code that demonstrate basic [[Emacs Lisp]]<br />
programming operations in the spirit of O'Reilly's Cookbook<br />
series of books. For every task addressed, a worked-out solution<br />
is presented as a short, focused, directly usable piece of code.<br />
<br />
All this stuff can be found elsewhere, but it is scattered about in<br />
libraries, manuals, etc. It would be helpful to have it here in one<br />
spot.<br />
<br />
These recipes should be pastable into the '''*scratch*''' buffer so that<br />
users can hit '''C-j''' and evaluate them step by step.<br />
<br />
== Strings ==<br />
<br />
The empty string (zero-length string, null string, ...):<br />
<br />
<syntaxhighlight lang="lisp"><br />
(zerop (string-match "" "")) ;; O(n)<br />
==> t<br />
<br />
(string-equal "" "") ;; O(n)?<br />
==> t<br />
<br />
(equal "" "") ;; O(n)?<br />
==> t<br />
<br />
(zerop (length "")) ;; O(1)<br />
==> t<br />
<br />
(eq "" "") ;; O(1)<br />
==> t<br />
</syntaxhighlight><br />
<br />
As a space and performance optimization, Emacs keeps an intern-ed copy<br />
of the empty string as a single object<br />
<br />
<syntaxhighlight lang="lisp"><br />
(eq "" (purecopy ""))<br />
==> t<br />
<br />
(eq "" (propertize "" 'face 'italic))<br />
==> t<br />
</syntaxhighlight><br />
<br />
=== Strings vs buffer content ===<br />
<br />
While it is quite common in other programming languages to work on<br />
strings contained in variables in Emacs it is even more idiomatic to<br />
work on strings in buffers. That's why the following contains examples<br />
of both.<br />
<br />
=== Substrings ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(substring "abcdefg" 0 3)<br />
==> "abc"<br />
(substring "abcdefg" -3 -1)<br />
==> "ef"<br />
</syntaxhighlight><br />
<br />
The TO argument is optional:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(substring "abcdefg" -3)<br />
==> "efg"<br />
</syntaxhighlight><br />
<br />
Buffers:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(with-temp-buffer<br />
(insert "abcdefg")<br />
(buffer-substring 2 4))<br />
==> "bc"<br />
</syntaxhighlight><br />
<br />
=== Processing characters ===<br />
<br />
Reversing a string:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(string-to-list "foo")<br />
==> (102 111 111)<br />
(reverse (string-to-list "foo"))<br />
==> (111 111 102)<br />
(apply 'string (reverse (string-to-list "foo")))<br />
==> "oof"<br />
</syntaxhighlight><br />
<br />
See CharacterProcessing and StringModification. See [[tr]] for an example of you sometimes need to mix strings and characters.<br />
<br />
Looking at characters in buffers:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(with-temp-buffer<br />
(insert "abcdefg")<br />
(goto-char (point-min))<br />
(while (not (= (char-after) ?b))<br />
(forward-char))<br />
(point))<br />
==> 2<br />
</syntaxhighlight><br />
<br />
=== Trim whitespace ===<br />
<br />
Trim whitespace from the end of a string:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(setq test-str "abcdefg ")<br />
(when (string-match "[ \t]*$" test-str)<br />
(message (concat "[" (replace-match "" nil nil test-str) "]")))<br />
</syntaxhighlight><br />
<br />
Trim whitespace from a string with a Perl-like chomp function:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun chomp (str)<br />
"Chomp leading and tailing whitespace from STR."<br />
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'"<br />
str)<br />
(setq str (replace-match "" t t str)))<br />
str)<br />
</syntaxhighlight><br />
<br />
=== Splitting strings ===<br />
<br />
The 'split-string' function is defined in 'subr.el' as<br />
<br />
<source lang="lisp"><br />
(defun split-string (string &optional separators omit-nulls)<br />
...)<br />
</source><br />
<br />
where 'separators' is a regular expression describing where to split the string. 'separators' defaults to white-space characters (spaces, form feeds, tabs, newlines, carriage returns, and vertical tabs). If 'omit-nulls' is set as 't' then zero-length strings are deleted from output.<br />
<br />
<source lang="lisp"><br />
(split-string "1 thing 2 say 3 words 4 you" "[1-9]")<br />
==> ("" " thing " " say " " words " " you")<br />
</source><br />
<br />
Omitting nulls:<br />
<source lang="lisp"><br />
(split-string "1 thing 2 say 3 words 4 you" "[1-9]" t)<br />
(" thing " " say " " words " " you")<br />
</source><br />
<br />
=== Joining strings ===<br />
<br />
Use `mapconcat' to join a list into a string using a separator ("glue") between elements in the string.<br />
<br />
Example:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(mapconcat 'identity '("" "home" "alex " "elisp" "erc") "/")<br />
==> "/home/alex /elisp/erc"<br />
</syntaxhighlight><br />
<br />
=== Serialization ===<br />
<br />
The basic idea is to convert forms to strings with `prin1-to-string' and convert it back from a string with `read'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(length (read (prin1-to-string (make-list 1000000 '(x)))))<br />
==> 1000000<br />
<br />
(read (prin1-to-string "Hello World!"))<br />
==> "Hello World!"<br />
</syntaxhighlight><br />
<br />
This only works in the simplest cases. Unfortunately, this doesn't work for all Emacs data types for programming or the editor.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(read (prin1-to-string (make-hash-table))) ;; Error before Emacs 23.<br />
==> #s(hash-table size 65 test eql rehash-size 1.5 [...] data ())<br />
<br />
(read (prin1-to-string (current-buffer)))<br />
==> Lisp error: (invalid-read-syntax "#")<br />
</syntaxhighlight><br />
<br />
=== Formatting ===<br />
<br />
== Killing text ==<br />
<br />
As the Emacs Lisp Manual says, "Most of the kill commands are primarily for<br />
interactive use [...] When you need to delete text for internal<br />
purposes within a Lisp function, you should normally use deletion<br />
functions, so as not to disturb the kill ring contents."<br />
<br />
The following mimic the `kill-' commands but without disturbing the kill ring.<br />
<br />
=== Delete region ===<br />
<br />
The Lisp equivalent of `kill-region' (`C-w') but without kill ring side effects::<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (region-beginning) (region-end))<br />
</syntaxhighlight> <br />
<br />
According to the ElispManual, "Few programs need to use the<br />
`region-beginning' and `region-end' functions." This is because<br />
Lisp code should not rely on nor "alter the mark unless altering<br />
the mark is part of the user-level functionality of the<br />
command. (And, in that case, this effect should be documented.)<br />
To remember a location for internal use in the Lisp program,<br />
store it in a Lisp variable. For example: [...]"<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-line 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight><br />
<br />
=== Delete line ===<br />
<br />
The equivalent of `kill-line' (`C-k') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-line 1)<br />
(forward-char -1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight><br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point)<br />
(save-excursion<br />
(forward-line 1)<br />
(forward-char -1)<br />
(point)))<br />
</syntaxhighlight> <br />
<br />
Or simplest of all,<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point) (line-end-position))<br />
</syntaxhighlight> <br />
<br />
The examples with `forward-line' are shown because the paradigm is used later, see below.<br />
<br />
=== Delete line backwards ===<br />
<br />
The equivalent of killing the line backwards (`C-0 C-k') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-line 0)<br />
(delete-region (point) beg))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (save-excursion<br />
(forward-line 0)<br />
(point))<br />
(point))<br />
</syntaxhighlight> <br />
<br />
Or simplest of all,<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (line-beginning-position) (point))<br />
</syntaxhighlight> <br />
<br />
<br />
=== Delete line to next line ===<br />
<br />
The equivalent of killing the line and the newline (`C-1 C-k') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-line 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point)<br />
(save-excursion<br />
(forward-line 1)<br />
(point)))<br />
</syntaxhighlight> <br />
<br />
=== Delete whole line ===<br />
<br />
The equivalent of `kill-whole-line' (`C-S-DEL') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (progn (forward-line 0)<br />
(point))))<br />
(forward-line 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (save-excursion<br />
(forward-line 0)<br />
(point))<br />
(save-excursion<br />
(forward-line 1)<br />
(point)))<br />
</syntaxhighlight> <br />
<br />
Or simplest of all,<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (line-beginning-position) (line-end-position))<br />
</syntaxhighlight> <br />
<br />
=== Delete word ===<br />
<br />
The equivalent of `kill-word' (`M-d') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-word 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point)<br />
(save-excursion<br />
(forward-word 1)<br />
(point)))<br />
</syntaxhighlight> <br />
<br />
=== Delete sentence ===<br />
<br />
The equivalent of `kill-sentence' (`M-k') but without kill ring side effects:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((beg (point)))<br />
(forward-sentence 1)<br />
(delete-region beg (point)))<br />
</syntaxhighlight> <br />
<br />
Alternatively, replacing the `let' with `save-excursion'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delete-region (point)<br />
(save-excursion<br />
(forward-sentence 1)<br />
(point)))<br />
</syntaxhighlight><br />
<br />
== Numbers ==<br />
<br />
=== String a number? ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun string-integer-p (string)<br />
(if (string-match "\\`[-+]?[0-9]+\\'" string)<br />
t<br />
nil))<br />
<br />
(string-integer-p "1234")<br />
==> t<br />
<br />
(string-integer-p "x1234")<br />
==> nil<br />
<br />
(string-integer-p "3.141592653589793")<br />
==> nil<br />
<br />
(defun string-float-p (string)<br />
(if (string-match "\\`[-+]?[0-9]+\\.[0-9]*\\'" string)<br />
t<br />
nil))<br />
<br />
(string-float-p "1234")<br />
==> nil<br />
<br />
(string-float-p "3.141592653589793")<br />
==> t<br />
<br />
(string-float-p ".1")<br />
==> nil<br />
<br />
(string-float-p "1.")<br />
==> t<br />
</syntaxhighlight> <br />
<br />
=== String to number ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun decimal-number (string)<br />
(let ((n (string-to-number string)))<br />
(if (and (zerop n)<br />
(not (string-match "\\`\\s-*0+\\.?0*\\s-*\\'" string)))<br />
nil<br />
n)))<br />
<br />
(decimal-number "536870911")<br />
==> 536870911<br />
<br />
(decimal-number "536870912")<br />
==> 536870912.0<br />
<br />
(decimal-number "3.141592653589793")<br />
==> 3.141592653589793<br />
<br />
(decimal-number "042")<br />
==> 42<br />
<br />
(decimal-number " 0 ")<br />
==> 0<br />
<br />
(decimal-number "000")<br />
==> 0<br />
<br />
(decimal-number "0.0")<br />
==> 0.0<br />
</syntaxhighlight> <br />
<br />
<br />
=== Random numbers ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(random 2) ;coin toss (0 or 1)<br />
(+ (random 6) 1) ;dice<br />
</syntaxhighlight> <br />
<br />
=== Put commas in numbers ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun group-number (num &optional size char)<br />
"Format NUM as string grouped to SIZE with CHAR."<br />
;; Based on code for `math-group-float' in calc-ext.el<br />
(let* ((size (or size 3))<br />
(char (or char ","))<br />
(str (if (stringp num)<br />
num<br />
(number-to-string num)))<br />
(pt (or (string-match "[^0-9a-zA-Z]" str) (length str))))<br />
(while (> pt size)<br />
(setq str (concat (substring str 0 (- pt size))<br />
char<br />
(substring str (- pt size)))<br />
pt (- pt size)))<br />
str))<br />
<br />
(group-number 299792458)<br />
==> "299,792,458"<br />
(group-number "149597870691" 4 " ")<br />
==> "1495 9787 0691"<br />
</syntaxhighlight> <br />
<br />
=== Incrementing numbers ===<br />
<br />
TODO<br />
<br />
== Dates and times ==<br />
<br />
=== Get today's date ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-time-string "%d %B %Y")<br />
</syntaxhighlight><br />
<br />
or <br />
<br />
<syntaxhighlight lang="lisp"><br />
(eshell/date)<br />
</syntaxhighlight><br />
<br />
=== Formatting dates ===<br />
<br />
Use the function `format-time-string' which is a build in function in both Emacsen and works like `strftime':<br />
<br />
<syntaxhighlight lang="lisp"><br />
;; Year-Month-Day:<br />
(insert (format-time-string "%Y-%m-%d"))<br />
;; Hour:Minutes:Seconds<br />
(insert (format-time-string "%H-%M-%S"))<br />
</syntaxhighlight> <br />
<br />
=== Conversions ===<br />
<br />
Read a date from a string.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((time (date-to-time "Tue, 27-Sep-83 12:35:59 EST")))<br />
(set-time-zone-rule t) ;; Use Universal time.<br />
(prog1 (format-time-string "%Y-%m-%d %T UTC" time)<br />
(set-time-zone-rule nil))) ;; Reset to default time zone.<br />
==> "1983-09-27 17:35:59 UTC"<br />
</syntaxhighlight> <br />
<br />
Decode a time object.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(decode-time (date-to-time "Tue, 27-Sep-83 12:35:59 EST"))<br />
==> (59 35 13 27 9 1983 2 t -14400)<br />
</syntaxhighlight> <br />
<br />
Get the seconds from the unix epoch.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((time (date-to-time "13 Feb 2009 23:31:30 UTC")))<br />
(float-time time))<br />
==> 1234585890.0<br />
</syntaxhighlight> <br />
<br />
Find the date for seconds from the unix epoch.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-time-string "%Y-%m-%d %T UTC" (seconds-to-time 1234585890))<br />
==> "2009-02-13 23:31:30 UTC"<br />
</syntaxhighlight> <br />
<br />
Find the date 30 seconds in the future.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-time-string "%Y-%m-%d %T UTC" (time-add (current-time)<br />
(seconds-to-time 30)))<br />
==> "2012-02-13 10:07:11 UTC"<br />
</syntaxhighlight> <br />
<br />
Formatting elapsed time in years, days, hours, minutes and seconds.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-seconds "%Y %D %h:%m:%s" (1- (* 367 24 3600)))<br />
==> "1 year 1 day 23:59:59"<br />
</syntaxhighlight> <br />
<br />
Find the days between two dates.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((days1 (time-to-days (date-to-time "Tue, 27-Sep-83 12:35:59 EST")))<br />
(days2 (time-to-days (date-to-time "2009-02-13 23:31:30 UTC"))))<br />
(- days2 days1))<br />
==> 9271<br />
</syntaxhighlight> <br />
<br />
Getting the day in the year.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(time-to-day-in-year (current-time))<br />
==> 44<br />
</syntaxhighlight> <br />
<br />
Build a date based on the day of the year.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(format-time-string "%j"<br />
(encode-time 0 0 0 44 1 2012))<br />
==> "044"<br />
</syntaxhighlight> <br />
<br />
=== Timers ===<br />
<br />
TODO<br />
<br />
Its funny that your example uses std::string beaucse it has the solution you're looking for.What you're trying to do is initialize a class member before initializing the base class, and you found that you can't. The typical way to get around this is to abandon hope of extending Foo and implement the wrapper in terms of Foo. (has-a vs. is-a) This solution has the annoyance of you needing to redeclare each and every method you want to use and then forwarding those calls to Foo, and you won't be able to use a FooWrapper in place of a Foo as well, meaning you may need to change a ton of references in your code. However, all you have to do is have FooWrapper expose its underlying Foo and you're good. (kinda like what string::c_str() does)Check out your copy of Effective C++. From the TOC I think item 40 discusses this.<br />
<br />
== Sequences ==<br />
<br />
Datatypes used to represent sequences of things:<br />
<br />
_____________________________________________<br />
| |<br />
| Sequence |<br />
| ______ ________________________________ |<br />
| | | | | |<br />
| | List | | Array | |<br />
| | | | ________ ________ | |<br />
| |______| | | | | | | |<br />
| | | Vector | | String | | |<br />
| | |________| |________| | |<br />
| | ____________ _____________ | |<br />
| | | | | | | |<br />
| | | Char-table | | Bool-vector | | |<br />
| | |____________| |_____________| | |<br />
| |________________________________| |<br />
|_____________________________________________|<br />
<br />
<br />
=== Lists ===<br />
<br />
List basics are explained on ListStructure.<br />
Lists can shrink and grow, but access to elements towards the end of the list is slow if the list is long.<br />
<br />
Use `cons' to append a new element to the front of a list.<br />
Use `nth' to access an element of the list.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((words '("fight" "foo" "for" "food!")))<br />
(when (string= "foo" (nth 1 words))<br />
(setq words (cons "bar" words)))<br />
words)<br />
==> ("bar" "fight" "foo" "for" "food!")<br />
</syntaxhighlight> <br />
<br />
See ListModification for more ways of changing a list.<br />
<br />
Iteration:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((result))<br />
(dolist (word '("fight" "foo" "for" "food!"))<br />
(when (string-match "o" word)<br />
(setq result (cons word result))))<br />
(nreverse result))<br />
==> ("foo" "for" "food!")<br />
</syntaxhighlight> <br />
<br />
Note how `cons' adds an element to the front of the list,<br />
so that usually the list has to be reversed after the loop.<br />
`nreverse' is particularly efficient because it does this<br />
destructively by swiveling pointers around. See<br />
DestructiveOperations for more about this.<br />
<br />
Copying:<br />
<br />
Use `copy-sequence' to make a copy of a list that won't change the<br />
elements of the original.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let* ((orig '((1 2) (3 4)))<br />
(copy (copy-sequence orig)))<br />
(setcdr copy '((5 6)))<br />
(list orig copy))<br />
==> (((1 2) (3 4)) ((1 2) (5 6)))<br />
</syntaxhighlight> <br />
<br />
However, the elements in the copy are still from the original.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let* ((orig '((1 2) (3 4)))<br />
(copy (copy-sequence orig)))<br />
(setcdr (cadr copy) '(0))<br />
(list orig copy))<br />
==> (((1 2) (3 0)) ((1 2) (3 0)))<br />
</syntaxhighlight> <br />
<br />
The function `copy-tree' is the recursive version of `copy-sequence'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let* ((orig '((1 2) (3 4)))<br />
(copy (copy-tree orig)))<br />
(setcdr (cadr copy) '(0))<br />
(list orig copy))<br />
==> (((1 2) (3 4)) ((1 2) (3 0)))<br />
</syntaxhighlight> <br />
<br />
Filtering:<br />
<br />
Emacs Lisp doesn't come with a `filter' function to keep elements that satisfy a conditional and excise the elements that do not satisfy it. One can use `mapcar' to iterate over a list with a conditional, and then use `delq' to remove the `nil' values.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun my-filter (condp lst)<br />
(delq nil<br />
(mapcar (lambda (x) (and (funcall condp x) x)) lst)))<br />
</syntaxhighlight> <br />
<br />
Therefore,<br />
<br />
<syntaxhighlight lang="lisp"><br />
(my-filter 'identity my-list)<br />
</syntaxhighlight> <br />
<br />
is equivalent to<br />
<br />
<syntaxhighlight lang="lisp"><br />
(delq nil my-list)<br />
</syntaxhighlight> <br />
<br />
For example:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((num-list '(1 'a 2 "nil" 3 nil 4)))<br />
(my-filter 'numberp num-list))<br />
==> (1 2 3 4)<br />
</syntaxhighlight> <br />
<br />
Actually the package cl-seq contains the functions `remove-if' and `remove-if-not'. The latter can be used instead of `my-filter'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((num-list '(1 'a 2 "nil" 3 nil 4)))<br />
(remove-if-not 'numberp num-list))<br />
==> (1 2 3 4)<br />
<br />
(let ((num-list '(1 'a 2 "nil" 3 nil 4)))<br />
(remove-if 'numberp num-list))<br />
==> ((quote a) "nil" nil)<br />
</syntaxhighlight> <br />
<br />
As an example here is the quick sort algorithm:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun quicksort (lst)<br />
"Implement the quicksort algorithm."<br />
(if (null lst) nil<br />
(let* ((spl (car lst))<br />
(rst (cdr lst))<br />
(smalp (lambda (x)<br />
(< x spl))))<br />
(append (quicksort (remove-if-not smalp rst))<br />
(list spl)<br />
(quicksort (remove-if smalp rst))))))<br />
<br />
(quicksort '(5 7 1 3 -9 8 7 -4 0))<br />
==> (-9 -4 0 1 3 5 7 7 8)<br />
</syntaxhighlight> <br />
<br />
Tranposing:<br />
<br />
Convert multiple lists into a list <br />
<br />
<syntaxhighlight lang="lisp"><br />
((lambda (&rest args)<br />
(mapcar (lambda (n)<br />
(delq nil (mapcar (lambda (arg) (nth n arg)) args)))<br />
(number-sequence 0 (1- (apply 'max (mapcar 'length args))))))<br />
'(1 2 3) '(a b c) '(A B C))<br />
==> ((1 a A) (2 b B) (3 c C))<br />
</syntaxhighlight> <br />
<br />
A more concise version is possible with the the higher-arity version of mapcar available with the `cl' library.<br />
<br />
<syntaxhighlight lang="lisp"><br />
((lambda (&rest args)<br />
(apply (function mapcar*) (function list) args))<br />
'(1 2 3) '(a b c) '(A B C))<br />
==> ((1 a A) (2 b B) (3 c C))<br />
</syntaxhighlight> <br />
<br />
Searching:<br />
<br />
Simply checking for existence of a value in a list can be done with<br />
`member' or `memq'.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((words '("fight" "foo" "for" "food!")))<br />
(car (member "for" words)))<br />
==> "for"<br />
<br />
(let ((re "\\wo\\b")<br />
(words '("fight" "foo" "for" "food!")))<br />
(consp (memq t<br />
(mapcar (lambda (s) (numberp (string-match re s))) words))))<br />
==> t<br />
</syntaxhighlight> <br />
<br />
In the latter, a more efficient algorithm would use a loop (a non-local exit).<br />
<br />
I don't think so. Normally you will open it up with latest veorisn, then save it in an earlier veorisn, that wat you can retain the 2008 veorisn with all the new options, and then convert it to an earlier. The improvements which are not handled by an earlier veorisn will be prompted when you try to save. You can lose layers or part of layers.<br />
<br />
=== Vectors ===<br />
<br />
Vectors are fixed in size but elements can be accessed in constant time.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((words ["fight" "foo" "for" "food!"]))<br />
(when (string= "foo" (aref words 1))<br />
(aset words 1 "bar"))<br />
words)<br />
==> ["fight" "bar" "for" "food!"]<br />
</syntaxhighlight> <br />
<br />
== Hashes ==<br />
<br />
Hashes map keys to values. In a way they are similar to alists, except<br />
they are more efficient for a large number of keys.<br />
<br />
More info is available on the HashMap page.<br />
<br />
=== Storing and retrieving keys and values ===<br />
<br />
By default, hash tables use `eql' to compare keys. This is not appropriate<br />
for strings: ##(eql "alex" "alex")## ==> nil. Thus, use `equal' in these cases:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((nick-table (make-hash-table :test 'equal)))<br />
(puthash "kensanata" "Alex Schroeder" nick-table)<br />
(gethash "kensanata" nick-table))<br />
==> "Alex Schroeder"<br />
</syntaxhighlight> <br />
<br />
Iterate:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((nick-table (make-hash-table :test 'equal))<br />
nicks)<br />
(puthash "kensanata" "Alex Schroeder" nick-table)<br />
(puthash "e1f" "Luis Fernandes" nick-table)<br />
(puthash "pjb" "Pascal J. Bourguignon" nick-table)<br />
(maphash (lambda (nick real-name)<br />
(setq nicks (cons nick nicks)))<br />
nick-table)<br />
nicks)<br />
==> ("pjb" "e1f" "kensanata")<br />
</syntaxhighlight> <br />
<br />
=== Sorting keys ===<br />
<br />
Use `maphash' to build up a list of keys, sort it, and then loop through<br />
the list:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(let ((nick-table (make-hash-table :test 'equal))<br />
nicks)<br />
(puthash "kensanata" "Alex Schroeder" nick-table)<br />
(puthash "e1f" "Luis Fernandes" nick-table)<br />
(puthash "pjb" "Pascal J. Bourguignon" nick-table)<br />
(maphash (lambda (nick real-name)<br />
(setq nicks (cons nick nicks)))<br />
nick-table)<br />
(mapcar (lambda (nick)<br />
(concat nick " => " (gethash nick nick-table)))<br />
(sort nicks 'string<)))<br />
==> ("e1f => Luis Fernandes"<br />
"kensanata => Alex Schroeder"<br />
"pjb => Pascal J. Bourguignon")<br />
</syntaxhighlight> <br />
<br />
== Files ==<br />
<br />
=== Read ===<br />
<br />
Processing a file is usually done with a temporary buffer:<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun process-file (file)<br />
"Read the contents of a file into a temp buffer and then do<br />
something there."<br />
(when (file-readable-p file)<br />
(with-temp-buffer<br />
(insert-file-contents file)<br />
(goto-char (point-min))<br />
(while (not (eobp))<br />
;; do something here with buffer content<br />
(forward-line)))))<br />
</syntaxhighlight> <br />
<br />
On the chance that a buffer may already be actively visiting the file,<br />
consider using `find-file-noselect'<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun file-string (file)<br />
"Read the contents of a file and return as a string."<br />
(with-current-buffer (find-file-noselect file)<br />
(buffer-string)))<br />
</syntaxhighlight> <br />
<br />
=== Write ===<br />
<br />
To write something to a file you can create a temporary buffer, insert the things to write there and write the buffer contents to a file. The following example read a string and a filename (with completion, but doesn't need to exist, see InteractiveCodeChar F) and write the string to that file.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun write-string-to-file (string file)<br />
(interactive "sEnter the string: \nFFile to save to: ")<br />
(with-temp-buffer<br />
(insert string)<br />
(when (file-writable-p file)<br />
(write-region (point-min)<br />
(point-max)<br />
file))))<br />
</syntaxhighlight> <br />
<br />
Maybe you are interested in word-count.el. It's cnirately to much foryour use-case but it is a great tool if you have some target lengthfor a document (e.g. diary entries).What I'm really missing in Emacs is some usage statistics. I canalready get an overview over my keybind habits with keyfreq but Iwould like that to be more comprehensive. Average buffer-length, timespent in different modes, time spent in files that are part of acertain directory, lines added etc. Maybe I'm just addicted to lifestatistics and this is not really useful. Who knows.<br />
<br />
=== Searching ===<br />
<br />
If you don't have grep, then you may need to write some Lisp which can find a match in a file.<br />
<br />
<syntaxhighlight lang="lisp"><br />
;; Visit file unless its already open.<br />
(with-current-buffer (find-file-noselect "~/.emacs")<br />
(save-excursion ;; Don't change location of point.<br />
(goto-char (point-min)) ;; From the beginning...<br />
(if (re-search-forward ".*load-path.*" nil t 1)<br />
(match-string-no-properties 0)<br />
(error "Search failed"))))<br />
==> "(add-to-list 'load-path \"/usr/share/emacs/site-lisp/\")"<br />
</syntaxhighlight> <br />
<br />
=== Filter ===<br />
<br />
=== Locking ===<br />
<br />
=== Stat ===<br />
<br />
An interface to the kernel's stat(2) is provided by the function file-attributes. The way times are represented may be a bit unexpected, though.<br />
<br />
=== Deleting ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(if (file-exists-p filename)<br />
(delete-file filename))<br />
</syntaxhighlight> <br />
<br />
=== Copy, move and rename ===<br />
<br />
== Directories ==<br />
<br />
=== Traversing ===<br />
<br />
<syntaxhighlight lang="lisp"><br />
(defun walk-path (dir action)<br />
"walk DIR executing ACTION with (dir file)"<br />
(cond ((file-directory-p dir)<br />
(or (char-equal ?/ (aref dir(1- (length dir))))<br />
(setq dir (file-name-as-directory dir)))<br />
(let ((lst (directory-files dir nil nil t))<br />
fullname file)<br />
(while lst<br />
(setq file (car lst))<br />
(setq lst (cdr lst))<br />
(cond ((member file '("." "..")))<br />
(t<br />
(and (funcall action dir file)<br />
(setq fullname (concat dir file))<br />
(file-directory-p fullname)<br />
(walk-path fullname action)))))))<br />
(t<br />
(funcall action<br />
(file-name-directory dir)<br />
(file-name-nondirectory dir)))))<br />
<br />
(defun walk-path-visitor (dir file)<br />
"Called by walk-path for each file found"<br />
(message (concat dir file)))<br />
<br />
(walk-path "~/" 'walk-path-visitor)<br />
</syntaxhighlight> <br />
<br />
=== Path splitting ===<br />
<br />
Splitting the path can be done with `split-string' and with the slash. Previously, Emacs would determine the character separating directory names with `directory-sep-char'. However, the variable is obselete with Emacs 21.1.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(split-string default-directory "/")<br />
==> ("" "usr" "share" "emacs" "22.2" "lisp" "")<br />
</syntaxhighlight><br />
<br />
For splitting a path variable, Emacs already has the `parse-colon-path' function.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(parse-colon-path (getenv "PATH"))<br />
==> ("/usr/lib/qt-3.3/bin/" "/usr/kerberos/bin/" "/usr/local/bin/"<br />
"/usr/bin/" "/bin/" "/usr/local/sbin/" "/usr/sbin/" "/sbin/")<br />
</syntaxhighlight><br />
<br />
== Processes ==<br />
<br />
=== Running a program ===<br />
<br />
Run a command without caring about its output.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(async-shell-command "emacs")<br />
</syntaxhighlight> <br />
<br />
Run a command and put its output in the current buffer.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(shell-command "seq 8 12 | sort" t)<br />
10<br />
11<br />
12<br />
8<br />
9<br />
</syntaxhighlight> <br />
<br />
Run a command and put its output in a new buffer.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(shell-command "seq 8 12 | sort"<br />
(get-buffer-create "*Standard output*"))<br />
</syntaxhighlight> <br />
<br />
Run a command return its output as a string.<br />
<br />
<syntaxhighlight lang="lisp"><br />
(shell-command-to-string "seq 8 12 | sort")<br />
</syntaxhighlight> <br />
<br />
XEmacs also comes with `exec-to-string'.<br />
<br />
=== Handling signals ===<br />
<br />
== Sockets ==<br />
<br />
=== Tcp client ===<br />
<br />
=== Tcp server ===<br />
<br />
Perhaps EmacsEchoServer and EmacsDaytimeServer can be useful here.<br />
<br />
== Keyboard events ==<br />
<br />
* Call function bound to key<br />
<br />
<syntaxhighlight lang="lisp"><br />
(funcall (key-binding (kbd "M-TAB")))<br />
</syntaxhighlight> <br />
<br />
or<br />
<br />
<syntaxhighlight lang="lisp"><br />
(call-interactively (key-binding (kbd "M-TAB")))<br />
</syntaxhighlight> <br />
<br />
[[Category:Customization]]<br />
[[Category:Intermediate]]</div>188.143.232.12https://wikemacs.org/index.php?title=IELM&diff=2927IELM2012-06-22T16:48:19Z<p>188.143.232.12: /* Show {{ModeLink|eldoc}} in IELM */</p>
<hr />
<div>{{package<br />
| name=IELM<br />
| description=Emacs Lisp REPL<br />
| author=David Smith<br />
| maintainer=<br />
| source=<br />
| in_emacs=yes<br />
}}<br />
<br />
'''IELM (Interactive Emacs Lisp Mode)''' is a nice mode that gives you an interactive [[Emacs Lisp]] shell (or a {{Acronym|REPL|Read-Eval-Print Loop}} if you prefer) that you can use for exploratory programming. You can start it by pressing {{Command|ielm}}. You'll be taken to a buffer named {{Buffer|*ielm*}}, where Emacs Lisp expressions you've entered will be evaluated on pressing the Return key. IELM offers some nice features like tab autocompletion of symbol names and the ability to span an expression over several lines. <br />
<br />
<!-----DONT REMOVE ANYTHING FROM THIS TEMPLATE ------------------------------><br />
<!-----FEW MONTHS, YEARS FROM WE CAN DELETE STUFF. NOT NOW ------------------><br />
<!-----YOU DON"T WANT WIKEMACS TO BE ANOTHER EMACSWIKI RIGHT ------------------><br />
<!-----PLEASE BE PATIENT AND CO-OPERATE FOR GREATER GOOD ------------------><br />
<br />
<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
= Basic setup =<br />
<br />
IELM is bundled with Emacs by default. No additional setup is required.<br />
<br />
Sarah / I'm trying to use this theme for a celint and it's generating this error: Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, mytheme_add_admin' was given in /home1/webdcmar/public_html/wp-includes/plugin.php on line 395Can you please double-check this and email me if you've corrected for the problem? The old version of Handgloves isn't even upload-able anymore. Just generates a string of errors. Thanks!<br />
<br />
= Common Customization =<br />
<!-- Customization common to all platforms goes here --><br />
<br />
One thing that many of the shooters on here don't take into aouccnt when selecting a remote trigger method is the absolute reliability that I get with my Pocket Wizards. Yesterday I shot an event with a very well-known coach of a college football team at one of his youth summer camps. This was a posed shot of the coach with each individual camper, and I had about 3-5 seconds between each shot, and only got one chance for each photo. I fired off 802 photos in a row with a set of Pocket Wizard (MultiMax) and a Nikon SB-800 on a light stand, and got 802 flash fires. That is 100.00% firing reliability, which is exactly what was required in this situation. Do you get that type of reliability with your eBay remotes?Richardp.s. I can post a shot of the setup, although it is so simple it is almost boring.<br />
<br />
= Recommended Reading =<br />
<!-- Only internal links. DO NOT insert EXTERNAL LINKS --><br />
* [[Emacs Lisp]]<br />
* [[REPL]]<br />
<br />
<br />
<!-------------------------------------------------------------------------><br />
<br />
= Tutorial Pages =<br />
[http://emacs-fu.blogspot.com/2011/03/ielm-repl-for-emacs.html IELM: A REPL for Emacs]<br />
<br />
<!-------------------------------------------------------------------------><br />
<!-- Add categories based on user-level (beginner etc), user-role (programming, emacs contributor etc), platform (windows, linux etc) or work flow (text editing, document authoring etc) --><br />
<br />
[[Category:Beginner]][[Category:Lisp]][[Category:Programming]]</div>188.143.232.12https://wikemacs.org/index.php?title=Quick_Tutorial&diff=2926Quick Tutorial2012-06-22T16:39:05Z<p>188.143.232.12: JiMixkaMtOZWR</p>
<hr />
<div>I merely wneatd to thank you yet again for the amazing website you have made here. Its full of ideas for those who are definitely interested in this particular subject, especially this very post. Your all amazingly sweet in addition to thoughtful of others in addition to the fact that reading your blog posts is a good delight to me. And what a generous treat! Ben and I usually have pleasure making use of your ideas in what we must do in a few weeks. Our checklist is a mile long which means that your tips is going to be put to beneficial use.</div>188.143.232.12https://wikemacs.org/index.php?title=Template:Command&diff=2922Template:Command2012-06-22T16:18:35Z<p>188.143.232.12: NccgezFg</p>
<hr />
<div>Hey Jeff, thanks for the moetinn!I haven't seen 404 pages done like this before, which is why I wrote about it. Sounds like Andrew has done something like this, and I'd actually love to see what he's doing (I'm guessing he couldn't give us the details without using the H word :) ).As to use in other template files, while I think that 404 pages are the most generally applicable and easily implemented examples, I also think private pages could be used in other places as well. I'm hoping this will spark more creative people to come up with even cooler uses of private pages.</div>188.143.232.12https://wikemacs.org/index.php?title=WikEmacs:Community_portal&diff=2914WikEmacs:Community portal2012-06-22T14:28:51Z<p>188.143.232.12: AfmGzLMWvQfvGr</p>
<hr />
<div>I have been surfing onlnie more than 3 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my view, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before.</div>188.143.232.12https://wikemacs.org/index.php?title=WikEmacs:Guidelines&diff=2913WikEmacs:Guidelines2012-06-22T14:28:03Z<p>188.143.232.12: aeAEyUUHd</p>
<hr />
<div>No towel racks one day (or week) is over, the importance of the towel can be uersdntood. In order to grasp the thin air only after washing your hands, please try to imagine every single time reaching for the towel. Initially embarrassed and you rack eventually towel and apparently (as a result) I understand that lack. Life without a rack next to the vanity top is truly frustrating experience. rn rnAccessibility features of modern society. Click the mouse button, all accessible to us in a gentle tap on the touch pad or laptop. When we need it desperately, why are ubiquitous towel, that is if we need to dry your hands after washing them, it should not escape us. These racks are to have access to the towel, that is their main feature. Although it initially looks like a very, spend a day without the rack, and you are connected, you may not Narimasure to understand when it comes to discomfort and dissatisfaction. More at</div>188.143.232.12https://wikemacs.org/index.php?title=Marmalade&diff=2896Marmalade2012-06-22T11:08:29Z<p>188.143.232.12: /* Project Pages */</p>
<hr />
<div>'''Marmalade''' is a [[package.el]] repository, supported by the Emacs community. It's best known feature is the ability to submit Emacs packages directly via Marmalade's web UI.<br />
<br />
== Basic setup ==<br />
<br />
<source lang="lisp"><br />
(require 'package)<br />
(add-to-list 'package-archives<br />
'("marmalade" . "http://marmalade-repo.org/packages/"))<br />
(package-initialize)<br />
</source><br />
<br />
== See Also ==<br />
<br />
* [[MELPA]]<br />
* [[package.el]]<br />
* [[el-get]]<br />
<br />
What host are you using? With the admin still under active dpeelovment we haven't been testing far and wide yet (just MAMP, a basic Dreamhost account, and a blank-slate Linode instance) but we plan on adding more hosts to the list to get it working under as many out-of-the-box host installs as possible. As for the problem at hand, check out the RewriteBase command in the .htaccess. That's most likely where you're running into issues if it wasn't set correctly (or if it was set to a symlink directory without +FollowSymlinks working) then you'd run into the problems you're describing<br />
<br />
== Tutorial Pages ==<br />
<br />
[[Category:Project Management]][[Category:Convenience]]</div>188.143.232.12https://wikemacs.org/index.php?title=Keyboard_macros&diff=2895Keyboard macros2012-06-22T11:04:12Z<p>188.143.232.12: /* Repeating a macro on every line in a region */</p>
<hr />
<div>{{Manual|emacs|Basic-Keyboard-Macro|Basic Keyboard Macro}}<br />
<br />
'''Keyboard macros''' can be used to automate or repeat tedious editing tasks in Emacs.<br />
<br />
==Example usage==<br />
Consider the standard <code>*scratch*</code> buffer:<br />
<br />
<pre><br />
;; This buffer is for notes you don't want to save, and for Lisp evaluation.<br />
;; If you want to create a file, visit that file with C-x C-f,<br />
;; then enter the text in that file's own buffer.<br />
</pre><br />
<br />
Suppose you want to remove the first occurrence of the letter "a" on every row in that piece of text. You could write a [[regular expression]] to do the job, but let's assume you want to use a keyboard macro this time.<br />
<br />
# Make sure [[point]] is at the start of the buffer.<br />
# Hit <code>C-x (</code> to start recording your macro. '''Note:''' If you hit <code>C-g</code> or if an error occurs, your keyboard macro recording will stop.<br />
# Hit <code>C-s</code> followed by <code>a</code> to find the first "a". Now, point is right after the first "a" in the text.<br />
# Hit backspace to delete that "a".<br />
<br />
The first occurrence of "a" of the first line has been deleted. Let's move point to the beginning of the next line and then stop recording.<br />
<br />
<ol start="5"><br />
<li>Hit <code>C-e C-f</code> to move point to the beginning of the next line.</li><br />
<li>Hit <code>C-x )</code> to finish the recording of our macro.</li><br />
</ol><br />
<br />
The macro you have just recorded performs the operation of removing the first occurrence of "a" it can find and then moving point to the next line.<br />
<br />
<ol start="7"><br />
<li>Hit <code>C-x e</code> once to call that macro.</li><br />
<li>Continue hitting <code>e</code> to call it several times. Hit any other key to get out of the macro repetition.</li><br />
</ol><br />
<br />
==Repeating a macro==<br />
To repeat a macro e.g. five times, you could hit <code>C-x e e e e e</code>. This could become tedious if you want to repeat it a greater amount of times, so an alternative is to provide a numeric argument to <code>C-x e</code>, e.g. <code>C-u 25 C-x e</code>.<br />
<br />
===Repeating until there's an error===<br />
Provide a <code>0</code> prefix argument to <code>C-x e</code> to execute a macro from point until there is an error, e.g. <code>C-u 0 C-x e</code> or <code>M-0 C-x e</code>. See [[prefix arguments]].<br />
<br />
Sarah / Also getting this error when I try to uptdae the General settings:Warning: Cannot modify header information headers already sent by (output started at /home1/webdcmar/public_html/wp-includes/plugin.php:395) in /home1/webdcmar/public_html/wp-includes/pluggable.php on line 897<br />
<br />
==Saving macros==<br />
{{Manual|emacs|Save-Keyboard-Macro|Save Keyboard Macro}}<br />
<br />
===By name===<br />
To give a macro a name which you can later call using <code>M-x</code>, hit <code>C-x C-k n</code>. Try to avoid strange characters in the name. Once you've given it a name, you can execute it using <code>M-x the-name-of-the-macro</code>.<br />
<br />
===Binding to a key===<br />
To bind a keyboard macro to a key using <code>C-x C-k b</code>. To avoid problems caused by overriding existing bindings, the key sequences <code>C-x C-k 0</code> through <code>C-x C-k 9</code> and <code>C-x C-k A</code> through <code>C-x C-k Z</code> are reserved for your own keyboard macro bindings. You can, however, bind a keyboard macro to whatever you like.<br />
<br />
===Saving it permanently===<br />
To save a keyboard macro for future Emacs sessions, go to your init file (or wherever you want to store it) and hit <code>M-x insert-kbd-macro</code>. Then enter the name of the macro you would like to save. This will insert Emacs Lisp code which defines the macro you chose, so you can use it in future sessions.<br />
<br />
Using the example in the beginning of this article, let's say you named that macro <code>remove-first-a</code>. If you use <code>insert-kbd-macro</code> to insert the Lisp for that macro, this is what would come up:<br />
<br />
<pre><br />
(fset 'remove-first-a<br />
(lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([19 97 13 backspace 5 6] 0 "%d")) arg)))<br />
</pre><br />
<br />
If you have bound the macro to a key as described in the previous section, you can generate the code for that as well by prefixing the insert-kbd-macro call with [[prefix argument|<code>C-u</code>]].<br />
<br />
[[Category:Intermediate]]<br />
[[Category:Editing]]</div>188.143.232.12https://wikemacs.org/index.php?title=Package.el&diff=2894Package.el2012-06-22T11:04:01Z<p>188.143.232.12: zYgyoXexG</p>
<hr />
<div>My spouse and i ended up being very frtauntoe when Peter managed to carry out his survey because of the ideas he had while using the weblog. It is now and again perplexing to simply continually be releasing hints which other folks may have been making money from. Therefore we do know we have the blog owner to be grateful to because of that. All the explanations you made, the straightforward web site menu, the relationships your site make it easier to foster it is mostly incredible, and it's really letting our son in addition to our family recognize that this concept is awesome, which is seriously indispensable. Many thanks for all the pieces!</div>188.143.232.12https://wikemacs.org/index.php?title=W3m-el&diff=2891W3m-el2012-06-22T10:29:57Z<p>188.143.232.12: HEjsttaSNfLEKzRYfzF</p>
<hr />
<div> Consider Emacs: it is extremely muaoldr and extremely extensible by virtue of it’s embedded Lisp interpreter. This is a strange thing to say in a paragraph talking about the Unix Philosophy, since Emacs comes from a completely different culture (MIT/ITS/Lisp vs Bell/PDP/C) and is virtually the antithesis of the Unix Way (everything in one process, communicating by function calls with rich data types).I love Emacs as much as anybody, but I wouldn't claim it has anything to do with Unix. We even had a funny name for the Unix port of Emacs ( Gosmacs ) way back when that wasn't the common place to run it!P: Have you ever tried building a medium-large-scale application (say, a project with 50-60 classes) with emacs and gcc? I’m sure it’s possible, with persistence Yes, I'm working on a large system right now not in C, but it has over 600 classes, and I don't know what an IDE could do for me that Emacs can't. find-tag is just as fast with 600 classes as with 6. Macros make O(n) editing tasks into O(1) editing tasks on any size project.What specific feature of an IDE helps you here? Everything I can think of that IDEs brag about, I do in Emacs every day.</div>188.143.232.12